[docs] example and title for tests (#191)

* [docs] example and title for tests

* fix cs
This commit is contained in:
Tomas Votruba 2021-06-09 16:45:03 +02:00 committed by GitHub
parent e31005a633
commit f3b3c8727f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 10 deletions

View File

@ -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

View File

@ -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;

View File

@ -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,

View File

@ -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;