Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 660942d

Browse files
authored
[Rector] Add rector to require-dev and use single autoload vendor for run PHPUnit (#1001)
1 parent f06d58d commit 660942d

6 files changed

Lines changed: 46 additions & 13 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"symfony/uid": "^6.4|^7.0|^8.0",
5151
"symfony/var-dumper": "^6.4|^7.0|^8.0",
5252
"symfony/yaml": "^6.4|^7.0|^8.0",
53-
"webmozart/assert": "^1.11"
53+
"webmozart/assert": "^1.11",
54+
"rector/rector": "^2.2"
5455
},
5556
"autoload": {
5657
"psr-4": {

tests/Integration/Maker/MakeFactoryTest.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ protected function tearDown(): void
5454
{
5555
parent::tearDown();
5656

57-
$removeSCAMock = static function(string $file): void {
57+
$removeSCAMock = function(string $file): void {
5858
if (\file_exists($file)) {
5959
\unlink($file);
60-
\rmdir(\dirname($file));
61-
\rmdir(\dirname($file, 2));
60+
$this->rrmdir(\dirname($file));
61+
$this->rrmdir(\dirname($file, 2));
6262
}
6363
};
6464
$removeSCAMock(self::PHPSTAN_PATH);
@@ -524,4 +524,36 @@ private function makeFactoryCommandTester(array $options = []): CommandTester
524524
{
525525
return new CommandTester((new Application(self::bootKernel($options)))->find('make:factory'));
526526
}
527+
528+
/**
529+
* Recursively remove a directory.
530+
* @see https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty
531+
*/
532+
private function rrmdir(string $dir): void
533+
{
534+
if (is_dir($dir))
535+
{
536+
$objects = scandir($dir);
537+
538+
if ($objects === false)
539+
{
540+
return;
541+
}
542+
543+
foreach ($objects as $object)
544+
{
545+
if ($object !== '.' && $object !== '..')
546+
{
547+
if (filetype($dir.'/'.$object) === 'dir') {
548+
$this->rrmdir($dir.'/'.$object);
549+
} else {
550+
unlink($dir.'/'.$object);
551+
}
552+
}
553+
}
554+
555+
reset($objects);
556+
rmdir($dir);
557+
}
558+
}
527559
}

utils/rector/phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ parameters:
77
level: 8
88
bootstrapFiles:
99
- ./../../vendor/autoload.php
10-
- ./../../bin/tools/rector/vendor/autoload.php
1110
excludePaths:
1211
- ./tests/Fixtures
13-
14-
ignoreErrors:
15-
- identifier: missingType.iterableValue

utils/rector/src/RemoveMethodCall/RemoveMethodCallRector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public function getNodeTypes() : array
2828
return [Node\Expr\MethodCall::class, Node\Expr\NullsafeMethodCall::class, Node\Stmt\Expression::class];
2929
}
3030

31-
/** @param Node\Expr\MethodCall|Node\Expr\NullsafeMethodCall|Node\Stmt\Expression $node */
31+
/**
32+
* @param Node\Expr\MethodCall|Node\Expr\NullsafeMethodCall|Node\Stmt\Expression $node
33+
* @return Node|null|\PhpParser\NodeVisitor::REMOVE_NODE
34+
*/
3235
public function refactor(Node $node) : Node|int|null
3336
{
3437
foreach ($this->removeMethodCalls as $removeMethodCall) {

utils/rector/src/RemoveWithoutAutorefreshCallRector.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ public function getNodeTypes() : array
2424
return [Node\Stmt\Expression::class];
2525
}
2626

27-
/** @param Node\Stmt\Expression $node */
28-
public function refactor(Node $node) : array|Node|null
27+
/**
28+
* @param Node\Stmt\Expression $node
29+
* @return Node\Stmt\Expression|array<Node\Stmt>|null
30+
*/
31+
public function refactor(Node $node) : Node\Stmt\Expression|null|array
2932
{
3033
$method = $node->expr;
3134

utils/rector/tests/bootstrap.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
require \dirname(__DIR__).'/../../bin/tools/rector/vendor/rector/rector/preload.php';
1312
require \dirname(__DIR__).'/../../vendor/autoload.php';
14-
require \dirname(__DIR__).'/../../bin/tools/rector/vendor/autoload.php';

0 commit comments

Comments
 (0)