Skip to content

Commit 835f6ff

Browse files
committed
cleanup fixtures with no change
1 parent 972239e commit 835f6ff

8 files changed

Lines changed: 20 additions & 145 deletions

File tree

bin/check-before-after-same-fixtures.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
require __DIR__ . '/../vendor/autoload.php';
66

77
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\ArgvInput;
9+
use Symfony\Component\Console\Output\ConsoleOutput;
10+
use Symfony\Component\Console\Style\SymfonyStyle;
811
use Symfony\Component\Finder\Finder;
912

1013
$invalidFixturePaths = [];
1114

12-
$symfonyStyle = new \Symfony\Component\Console\Style\SymfonyStyle(
13-
new \Symfony\Component\Console\Input\ArgvInput(),
14-
new \Symfony\Component\Console\Output\ConsoleOutput()
15-
);
15+
$symfonyStyle = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
1616

1717
$testFixtureFiles = (new Finder())
1818
->files()
1919
->in([__DIR__ . '/../tests', __DIR__ . '/../rules-tests'])
2020
->name('*.php.inc')
21+
->sortByName()
2122
->getIterator();
2223

2324
foreach ($testFixtureFiles as $testFixtureFile) {
2425
if (! str_contains($testFixtureFile->getContents(), '-----')) {
2526
continue;
2627
}
2728

28-
$parts = preg_split('/^\s*-{5,}\s*$/m', file_get_contents($testFixtureFile->getRealPath()));
29+
$parts = preg_split('/^\s*-----\s*$/m', file_get_contents($testFixtureFile->getRealPath()));
2930
if (count($parts) !== 2) {
3031
continue;
3132
}
@@ -34,15 +35,18 @@
3435
continue;
3536
}
3637

37-
$invalidFixturePaths[] = $testFixtureFile->getRealPath();
38+
$invalidFixturePaths[] = substr($testFixtureFile->getRealPath(), strlen(getcwd()) + 1);
39+
//$testFixtureFile->getRealPath();
3840
}
3941

4042
if ($invalidFixturePaths === []) {
4143
$symfonyStyle->success('All fixtures are valid');
4244
exit(Command::SUCCESS);
4345
}
4446

45-
$symfonyStyle->error('The following fixtures have the same before and after content. Remove the part after "-----" to fix them');
47+
$symfonyStyle->error(
48+
'The following fixtures have the same before and after content. Remove the part after "-----" to fix them'
49+
);
4650

4751
$symfonyStyle->listing($invalidFixturePaths);
4852

rules-tests/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector/Fixture/static_property.php.inc

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,3 @@ class StaticProperty
1212
return $this::$privateProperty;
1313
}
1414
}
15-
16-
?>
17-
-----
18-
<?php
19-
20-
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;
21-
22-
class StaticProperty
23-
{
24-
public static $publicProperty;
25-
protected static $protectedProperty;
26-
27-
public function foo()
28-
{
29-
return $this::$privateProperty;
30-
}
31-
}
32-
33-
?>

rules-tests/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector/Fixture/final_private_constructor.php.inc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,3 @@ abstract class FinalPrivate
88
{
99
}
1010
}
11-
12-
?>
13-
-----
14-
<?php
15-
16-
namespace Rector\Tests\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector\Fixture;
17-
18-
abstract class FinalPrivate
19-
{
20-
final private function __construct()
21-
{
22-
}
23-
}
24-
25-
?>

rules-tests/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector/Fixture/fixture.php.inc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ declare(strict_types=1);
44

55
namespace Rector\Tests\Php85\Rector\FuncCall\RemoveFinfoBufferContextArgRector\Fixture;
66

7-
finfo_buffer($finfo, $fileContents);
8-
finfo_buffer($finfo, $fileContents, FILEINFO_NONE);
97
finfo_buffer($finfo, $fileContents, FILEINFO_NONE, $context);
108
finfo_buffer($finfo, $fileContents, FILEINFO_NONE, context: $context);
119
finfo_buffer($finfo, $fileContents, flags: FILEINFO_NONE, context: $context);
1210
finfo_buffer($finfo, $fileContents, context: $context);
1311
finfo_buffer($finfo, $fileContents, context: $context, flags: FILEINFO_NONE);
14-
finfo_buffer(...[$finfo, $fileContents]);
15-
finfo_buffer(...[$finfo, $fileContents, $context]);
16-
finfo_buffer(...[$finfo, $fileContents, FILEINFO_NONE, $context]);
1712

1813
function foo(\finfo $finfo): void
1914
{
@@ -22,9 +17,6 @@ function foo(\finfo $finfo): void
2217
$finfo->buffer($fileContents, flags: FILEINFO_NONE, context: $context);
2318
$finfo->buffer($fileContents, context: $context);
2419
$finfo->buffer($fileContents, context: $context, flags: FILEINFO_NONE);
25-
$finfo->buffer(...[$fileContents]);
26-
$finfo->buffer(...[$fileContents, $context]);
27-
$finfo->buffer(...[$fileContents, FILEINFO_NONE, $context]);
2820
}
2921

3022
?>
@@ -35,16 +27,11 @@ declare(strict_types=1);
3527

3628
namespace Rector\Tests\Php85\Rector\FuncCall\RemoveFinfoBufferContextArgRector\Fixture;
3729

38-
finfo_buffer($finfo, $fileContents);
39-
finfo_buffer($finfo, $fileContents, FILEINFO_NONE);
4030
finfo_buffer($finfo, $fileContents, FILEINFO_NONE);
4131
finfo_buffer($finfo, $fileContents, FILEINFO_NONE);
4232
finfo_buffer($finfo, $fileContents, flags: FILEINFO_NONE);
4333
finfo_buffer($finfo, $fileContents);
4434
finfo_buffer($finfo, $fileContents, flags: FILEINFO_NONE);
45-
finfo_buffer(...[$finfo, $fileContents]);
46-
finfo_buffer(...[$finfo, $fileContents, $context]);
47-
finfo_buffer(...[$finfo, $fileContents, FILEINFO_NONE, $context]);
4835

4936
function foo(\finfo $finfo): void
5037
{
@@ -53,9 +40,6 @@ function foo(\finfo $finfo): void
5340
$finfo->buffer($fileContents, flags: FILEINFO_NONE);
5441
$finfo->buffer($fileContents);
5542
$finfo->buffer($fileContents, flags: FILEINFO_NONE);
56-
$finfo->buffer(...[$fileContents]);
57-
$finfo->buffer(...[$fileContents, $context]);
58-
$finfo->buffer(...[$fileContents, FILEINFO_NONE, $context]);
5943
}
6044

6145
?>

rules-tests/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector/Fixture/skip_different_cases.php.inc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,3 @@ function bar($otherObject): void
2121
$finfo->buffer($fileContents, FILEINFO_NONE, context: $context);
2222
$finfo->buffer($fileContents, flags: FILEINFO_NONE, context: $context);
2323
}
24-
25-
?>
26-
-----
27-
<?php
28-
29-
declare(strict_types=1);
30-
31-
namespace Rector\Tests\Php85\Rector\FuncCall\RemoveFinfoBufferContextArgRector\Fixture;
32-
33-
finfo_file($finfo, $fileContents, FILEINFO_NONE, $context);
34-
finfo_file($finfo, $fileContents, FILEINFO_NONE, context: $context);
35-
finfo_file($finfo, $fileContents, flags: FILEINFO_NONE, context: $context);
36-
37-
function foo(\finfo $finfo): void
38-
{
39-
$finfo->file($fileContents, FILEINFO_NONE, $context);
40-
$finfo->file($fileContents, FILEINFO_NONE, context: $context);
41-
$finfo->file($fileContents, flags: FILEINFO_NONE, context: $context);
42-
}
43-
44-
function bar($otherObject): void
45-
{
46-
$finfo->buffer($fileContents, FILEINFO_NONE, $context);
47-
$finfo->buffer($fileContents, FILEINFO_NONE, context: $context);
48-
$finfo->buffer($fileContents, flags: FILEINFO_NONE, context: $context);
49-
}
50-
51-
?>

rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/FixtureUnion/array_reverse_index.php.inc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,3 @@ final class ArrayReverseIndex
2121
return sprintf('%d-%s', $index, $uri);
2222
}
2323
}
24-
25-
?>
26-
-----
27-
<?php
28-
29-
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureUnion;
30-
31-
final class ArrayReverseIndex
32-
{
33-
public function run()
34-
{
35-
$parts = array_reverse(explode('/', '/some/test/url'));
36-
foreach ($parts as $index => $uri) {
37-
if ($index === 0) {
38-
continue;
39-
}
40-
41-
$this->someOtherMethod($index, $uri);
42-
}
43-
}
44-
45-
private function someOtherMethod(int $index, string $uri)
46-
{
47-
return sprintf('%d-%s', $index, $uri);
48-
}
49-
}
50-
51-
?>

rules-tests/TypeDeclaration/Rector/Closure/AddClosureVoidReturnTypeWhereNoReturnRector/Fixture/return_inside_inner_function.php.inc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,3 @@ final class ReturnInsideInnerFunction
1616
};
1717
}
1818
}
19-
20-
?>
21-
-----
22-
<?php
23-
24-
namespace Rector\Tests\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector\Fixture;
25-
26-
final class ReturnInsideInnerFunction
27-
{
28-
public function getValues()
29-
{
30-
$result = function () {
31-
$value = 1000;
32-
if ($value) {
33-
return;
34-
}
35-
36-
return 10;
37-
};
38-
}
39-
}
40-
41-
?>

rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function refactor(Node $node): ?Node
6363
return null;
6464
}
6565

66-
if ($node instanceof FuncCall && ! $this->isName($node->name, 'finfo_buffer')) {
66+
if (! $this->isName($node->name, 'finfo_buffer')) {
6767
return null;
6868
}
6969

@@ -88,44 +88,44 @@ public function provideMinPhpVersion(): int
8888
}
8989

9090
/**
91-
* @param FuncCall|MethodCall $funcCall
91+
* @param FuncCall|MethodCall $callLike
9292
*/
93-
private function removeContextArg(CallLike $funcCall): bool
93+
private function removeContextArg(CallLike $callLike): bool
9494
{
9595
// In `finfo::buffer` method calls, the first parameter, compared to `finfo_buffer`, does not exist.
9696
$methodArgCorrection = 0;
97-
if ($funcCall instanceof MethodCall) {
97+
if ($callLike instanceof MethodCall) {
9898
$methodArgCorrection = -1;
9999
}
100100

101-
if (count($funcCall->args) <= 2 + $methodArgCorrection) {
101+
if (count($callLike->args) <= 2 + $methodArgCorrection) {
102102
return false;
103103
}
104104

105105
// Cannot handle variadic args
106-
foreach ($funcCall->args as $position => $arg) {
106+
foreach ($callLike->args as $position => $arg) {
107107
if (! $arg instanceof Arg) {
108108
return false;
109109
}
110110
}
111111

112112
/** @var array<Arg> $args */
113-
$args = $funcCall->args;
113+
$args = $callLike->args;
114114

115115
// Argument 3 ($flags) and argument 4 ($context) are optional, thus named parameters must be considered
116116
if (! $this->argsAnalyzer->hasNamedArg($args)) {
117117
if (count($args) < 4 + $methodArgCorrection) {
118118
return false;
119119
}
120120

121-
unset($funcCall->args[3 + $methodArgCorrection]);
121+
unset($callLike->args[3 + $methodArgCorrection]);
122122

123123
return true;
124124
}
125125

126126
foreach ($args as $position => $arg) {
127127
if ($arg->name instanceof Identifier && $arg->name->name === 'context') {
128-
unset($funcCall->args[$position]);
128+
unset($callLike->args[$position]);
129129

130130
return true;
131131
}

0 commit comments

Comments
 (0)