Skip to content
Merged
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
18 changes: 4 additions & 14 deletions config/set/php-version-based.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use PhpParser\Node\Expr\Cast\Int_;
use PhpParser\Node\Expr\Cast\String_;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Arguments\ValueObject\ReplaceFuncCallArgumentDefaultValue;
use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
use Rector\CodingStyle\Rector\Closure\ClosureDelegatingCallToFirstClassCallableRector;
Expand Down Expand Up @@ -95,6 +93,8 @@
use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector;
use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector;
use Rector\Php80\Rector\FuncCall\ClassOnObjectRector;
use Rector\Php80\Rector\FuncCall\GetHeadersArgumentFormatRector;
use Rector\Php80\Rector\FuncCall\VersionCompareFuncCallArgumentRector;
use Rector\Php80\Rector\Identical\StrEndsWithRector;
use Rector\Php80\Rector\Identical\StrStartsWithRector;
use Rector\Php80\Rector\NotIdentical\StrContainsRector;
Expand Down Expand Up @@ -270,6 +270,8 @@
ClassOnThisVariableObjectRector::class,
ConsistentImplodeRector::class,
OptionalParametersAfterRequiredRector::class,
VersionCompareFuncCallArgumentRector::class,
GetHeadersArgumentFormatRector::class,

// PHP 8.1
ReturnNeverTypeRector::class,
Expand Down Expand Up @@ -468,18 +470,6 @@
'pg_setclientencoding' => 'pg_set_client_encoding',
], PhpVersion::PHP_80);

$rectorConfig->ruleWithConfigurationPhpVersionBound(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'lte', 'le'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '', '!='),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '!', '!='),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'g', 'gt'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'l', 'lt'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'n', 'ne'),
new ReplaceFuncCallArgumentDefaultValue('get_headers', 1, 0, false),
new ReplaceFuncCallArgumentDefaultValue('get_headers', 1, 1, true),
], PhpVersion::PHP_80);

// PHP 8.5
$rectorConfig->ruleWithConfigurationPhpVersionBound(RemoveFuncCallArgRector::class, [
// https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_key_length_parameter_of_openssl_pkey_derive
Expand Down
19 changes: 4 additions & 15 deletions config/set/php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Arguments\ValueObject\ReplaceFuncCallArgumentDefaultValue;
use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
use Rector\Config\RectorConfig;
Expand All @@ -18,6 +16,8 @@
use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector;
use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector;
use Rector\Php80\Rector\FuncCall\ClassOnObjectRector;
use Rector\Php80\Rector\FuncCall\GetHeadersArgumentFormatRector;
use Rector\Php80\Rector\FuncCall\VersionCompareFuncCallArgumentRector;
use Rector\Php80\Rector\Identical\StrEndsWithRector;
use Rector\Php80\Rector\Identical\StrStartsWithRector;
use Rector\Php80\Rector\NotIdentical\StrContainsRector;
Expand Down Expand Up @@ -47,6 +47,8 @@
ClassOnThisVariableObjectRector::class,
ConsistentImplodeRector::class,
OptionalParametersAfterRequiredRector::class,
VersionCompareFuncCallArgumentRector::class,
GetHeadersArgumentFormatRector::class,
]);

$rectorConfig
Expand Down Expand Up @@ -91,17 +93,4 @@
'pg_result' => 'pg_fetch_result',
'pg_setclientencoding' => 'pg_set_client_encoding',
]);

$rectorConfig
->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'lte', 'le'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '', '!='),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '!', '!='),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'g', 'gt'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'l', 'lt'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'n', 'ne'),
new ReplaceFuncCallArgumentDefaultValue('get_headers', 1, 0, false),
new ReplaceFuncCallArgumentDefaultValue('get_headers', 1, 1, true),
]);
};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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

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

class FormatArgument
{
public function run($url)
{
get_headers($url, 0);
get_headers($url, 1);
}
}

?>
-----
<?php

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

class FormatArgument
{
public function run($url)
{
get_headers($url, false);
get_headers($url, true);
}
}

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

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

class SkipGetHeaders
{
public function run($url, $format)
{
get_headers($url);
get_headers($url, $format);
get_headers($url, true);
get_headers(...);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Rector\Tests\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector;
namespace Rector\Tests\Php80\Rector\FuncCall\GetHeadersArgumentFormatRector;

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

final class FunctionArgumentDefaultValueReplacerRectorTest extends AbstractRectorTestCase
final class GetHeadersArgumentFormatRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
Expand Down
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\GetHeadersArgumentFormatRector;

return RectorConfig::configure()
->withRules([GetHeadersArgumentFormatRector::class]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

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

class OperatorAliases
{
public function run()
{
version_compare(PHP_VERSION, '5.6', 'gte');
version_compare(PHP_VERSION, '5.6', 'lte');
version_compare(1, 2, '');
version_compare(1, 2, '!');
version_compare(PHP_VERSION, '5.6', 'g');
version_compare(PHP_VERSION, '5.6', 'l');
version_compare(PHP_VERSION, '5.6', 'n');
}
}

?>
-----
<?php

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

class OperatorAliases
{
public function run()
{
version_compare(PHP_VERSION, '5.6', 'ge');
version_compare(PHP_VERSION, '5.6', 'le');
version_compare(1, 2, '!=');
version_compare(1, 2, '!=');
version_compare(PHP_VERSION, '5.6', 'gt');
version_compare(PHP_VERSION, '5.6', 'lt');
version_compare(PHP_VERSION, '5.6', 'ne');
}
}

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

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

class SkipVersionCompare
{
public function run()
{
version_compare($a, $b, $c);
version_compare(1, 2);
version_compare(PHP_VERSION, '5.6', 'ge');
version_compare(...);
}
}
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\VersionCompareFuncCallArgumentRector;

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

final class VersionCompareFuncCallArgumentRectorTest 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,9 @@
<?php

declare(strict_types=1);

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

return RectorConfig::configure()
->withRules([VersionCompareFuncCallArgumentRector::class]);
3 changes: 3 additions & 0 deletions rules/Arguments/ArgumentDefaultValueReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
use Rector\Reflection\ReflectionResolver;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;

/**
* @api
*/
final readonly class ArgumentDefaultValueReplacer
{
public function __construct(
Expand Down
Loading
Loading