Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/set/php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector;
use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector;
use Rector\Php80\Rector\FuncCall\ClassOnObjectRector;
use Rector\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector;
use Rector\Php80\Rector\Identical\StrEndsWithRector;
use Rector\Php80\Rector\Identical\StrStartsWithRector;
use Rector\Php80\Rector\NotIdentical\StrContainsRector;
Expand All @@ -34,6 +35,7 @@
StrEndsWithRector::class,
StringableForToStringRector::class,
ClassOnObjectRector::class,
ConvertAssignToNamedArgumentRector::class,
GetDebugTypeRector::class,
RemoveUnusedVariableInCatchRector::class,
ClassPropertyAssignToConstructorPromotionRector::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class ConvertAssignToNamedArgumentRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

fn () => in_array('foo', ['bar'], $strict = true);

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

fn () => in_array('foo', ['bar'], strict: true);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

function basicFunctionCall()
{
in_array('foo', $array, $strict = true);
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

function basicFunctionCall()
{
in_array('foo', $array, strict: true);
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

str_replace($search = 'old', $replace = 'new', $subject = 'old text');
substr($string = 'hello', $offset = 1, $length = 3);

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

str_replace(search: 'old', replace: 'new', subject: 'old text');
substr(string: 'hello', offset: 1, length: 3);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

use Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source\SomeClass;

/** @var SomeClass $service */
$service->process($data = 'test', $options = ['key' => 'value']);

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

use Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source\SomeClass;

/** @var SomeClass $service */
$service->process(data: 'test', options: ['key' => 'value']);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

function (): bool {
return in_array('foo', ['bar'], $strict = true);
};

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

function (): bool {
return in_array('foo', ['bar'], strict: true);
};

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', ['bar'], $strict = true);
in_array('foo', ['bar'], $strict = true);

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', ['bar'], strict: true);
in_array('foo', ['bar'], strict: true);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

in_array('foo', ['bar'], $strict = true);

?>
-----
<?php

in_array('foo', ['bar'], strict: true);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

use Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source\SomeClass;

final readonly class Service
{
public function __construct(private SomeClass $someClass) {}

public function methodCall()
{
$this->someClass->process($data = 'test', $options = ['key' => 'value']);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

use Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source\SomeClass;

final readonly class Service
{
public function __construct(private SomeClass $someClass) {}

public function methodCall()
{
$this->someClass->process(data: 'test', options: ['key' => 'value']);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

substr($string = str_repeat('a', $times = 10), $offset = 2, $length = 5);

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

substr(string: str_repeat('a', times: 10), offset: 2, length: 5);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', $haystack = [], strict: true);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

unknownFunction($param1 = 'value1', $param2 = 'value2');

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', ['bar'], $foo = true);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', ['bar'], $strict = true);
echo $strict;

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

array_merge($array = ['a'], $second = ['b'], $third = ['c']);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

use Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source\SomeClass;

SomeClass::staticMethod('foo', $b = 'value');

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

use Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source\SomeClass;

SomeClass::staticMethod('foo', b: 'value');

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', ['bar'], $strict = true);
in_array('foo', ['bar'], $strict = ! $strict);

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Fixture;

in_array('foo', ['bar'], $strict = true);
in_array('foo', ['bar'], strict: ! $strict);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector\Source;

class SomeClass
{
public static function staticMethod(string $a, string $b): void {}
public function process(string $data, array $options = []): void {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php80\Rector\FuncCall\ConvertAssignToNamedArgumentRector;

return RectorConfig::configure()
->withRules([ConvertAssignToNamedArgumentRector::class]);
Loading
Loading