mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 08:20:53 +00:00
[docs] example and title for tests (#191)
* [docs] example and title for tests * fix cs
This commit is contained in:
parent
e31005a633
commit
f3b3c8727f
|
@ -29,7 +29,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
final class MyFirstRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ final class MyFirstRector extends AbstractRector
|
|||
}
|
||||
|
||||
/**
|
||||
* From this method documentation is generated.
|
||||
* This method helps other to understand the rule and to generate documentation.
|
||||
*/
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
|
@ -78,7 +78,24 @@ final class MyFirstRector extends AbstractRector
|
|||
}
|
||||
```
|
||||
|
||||
This is how the file structure should look like:
|
||||
|
||||
## File Structure
|
||||
|
||||
This is how the file structure for custom rule in your own project will look like:
|
||||
|
||||
```bash
|
||||
/src/
|
||||
/YourCode.php
|
||||
/utils
|
||||
/rector
|
||||
/src
|
||||
/Rector
|
||||
MyFirstRector.php
|
||||
rector.php
|
||||
composer.json
|
||||
```
|
||||
|
||||
Writing test saves you lot of time in future debugging. Here is a file structure with tests:
|
||||
|
||||
```bash
|
||||
/src/
|
||||
|
@ -91,11 +108,17 @@ This is how the file structure should look like:
|
|||
/tests
|
||||
/Rector
|
||||
/MyFirstRector
|
||||
/Fixture
|
||||
test_fixture.php.inc
|
||||
/config
|
||||
config.php
|
||||
MyFirstRectorTest.php
|
||||
rector.php
|
||||
composer.json
|
||||
```
|
||||
|
||||
## Update `composer.json`
|
||||
|
||||
We also need to load Rector rules in `composer.json`:
|
||||
|
||||
```json
|
||||
|
|
|
@ -137,10 +137,7 @@ final class PhpAttributeGroupFactory
|
|||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
return array_map(
|
||||
fn ($item) => $this->normalizeNodeValue($item),
|
||||
$value
|
||||
);
|
||||
return array_map(fn ($item) => $this->normalizeNodeValue($item), $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
|
|
@ -190,8 +190,7 @@ CODE_SAMPLE
|
|||
Array_ $array,
|
||||
ArrayItem $arrayItem,
|
||||
int | string $position
|
||||
): Variable
|
||||
{
|
||||
): Variable {
|
||||
/** @var Scope $nodeScope */
|
||||
$nodeScope = $array->getAttribute(AttributeKey::SCOPE);
|
||||
// The variable name will be item0Unpacked, item1Unpacked, etc,
|
||||
|
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace Rector\DowngradePhp80\Rector\Expression;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Match_;
|
||||
use PhpParser\Node\MatchArm;
|
||||
|
|
Loading…
Reference in New Issue
Block a user