Skip to content

Commit 9650da2

Browse files
[DowngradePhp80/Php73] Handle comma removed on combination DowngradeNamedArgumentRector + DowngradeTrailingCommasInFunctionCallsRector (#281)
* [DowngradePhp80/Php73] Handle comma removed on combination DowngradeNamedArgumentRector + DowngradeTrailingCommasInFunctionCallsRector * [ci-review] Rector Rectify * Fix --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 2d0ffeb commit 9650da2

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function fillFromNamedArgs(
5656
$currentArg->value,
5757
$currentArg->byRef,
5858
$currentArg->unpack,
59-
$currentArg->getAttributes(),
59+
[],
6060
null
6161
);
6262
}

rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function resolveFromReflection(
4545

4646
foreach ($currentArgs as $key => $arg) {
4747
if (! $arg->name instanceof Identifier) {
48-
$unnamedArgs[$key] = new Arg($arg->value, $arg->byRef, $arg->unpack, $arg->getAttributes(), null);
48+
$unnamedArgs[$key] = new Arg($arg->value, $arg->byRef, $arg->unpack, [], null);
4949

5050
continue;
5151
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\DowngradeNamedTrailing;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class DowngradeNamedTrailingTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Rector\Tests\Issues\DowngradeNamedTrailing\Fixture;
4+
5+
class Fixture
6+
{
7+
public function __construct(
8+
protected string $type,
9+
array $data = [],
10+
protected ?string $id = null,
11+
protected ?int $version = null,
12+
protected ?string $key = null,
13+
protected ?string $internalId = null,
14+
protected ?string $externalId = null,
15+
) {
16+
$this->setData($data);
17+
}
18+
}
19+
20+
$contents = new Fixture(
21+
$content->getType(),
22+
id: $content->getId(),
23+
data: ['error' => $e->getMessage()]
24+
);
25+
26+
?>
27+
-----
28+
<?php
29+
30+
namespace Rector\Tests\Issues\DowngradeNamedTrailing\Fixture;
31+
32+
class Fixture
33+
{
34+
public function __construct(
35+
protected string $type,
36+
array $data = [],
37+
protected ?string $id = null,
38+
protected ?int $version = null,
39+
protected ?string $key = null,
40+
protected ?string $internalId = null,
41+
protected ?string $externalId = null,
42+
) {
43+
$this->setData($data);
44+
}
45+
}
46+
47+
$contents = new Fixture(
48+
$content->getType(),
49+
['error' => $e->getMessage()],
50+
$content->getId()
51+
);
52+
53+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\DowngradePhp73\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector;
7+
use Rector\DowngradePhp80\Rector\MethodCall\DowngradeNamedArgumentRector;
8+
9+
return RectorConfig::configure()
10+
->withRules([DowngradeNamedArgumentRector::class, DowngradeTrailingCommasInFunctionCallsRector::class]);

0 commit comments

Comments
 (0)