mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-30 07:50:53 +00:00
[Transform] Move FunctionCallToConstantRector to FuncCallToConstFetchRector (#5642)
This commit is contained in:
parent
2205766dbc
commit
e571128b85
|
@ -18,7 +18,6 @@ use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
|
|||
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncCallToVariadicRector;
|
||||
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
|
||||
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
|
||||
use Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector;
|
||||
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
|
||||
use Rector\CodingStyle\Rector\Function_\CamelCaseFunctionNamingToUnderscoreRector;
|
||||
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
|
||||
|
@ -34,6 +33,7 @@ use Rector\CodingStyle\Rector\Ternary\TernaryConditionVariableAssignmentRector;
|
|||
use Rector\CodingStyle\Rector\Use_\RemoveUnusedAliasRector;
|
||||
use Rector\CodingStyle\Rector\Use_\SplitGroupedUseImportsRector;
|
||||
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
|
||||
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
|
@ -66,9 +66,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(VersionCompareFuncCallToConstantRector::class);
|
||||
$services->set(UseMessageVariableForSprintfInSymfonyStyleRector::class);
|
||||
|
||||
$services->set(FunctionCallToConstantRector::class)
|
||||
$services->set(FuncCallToConstFetchRector::class)
|
||||
->call('configure', [[
|
||||
FunctionCallToConstantRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
FuncCallToConstFetchRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
'php_sapi_name' => 'PHP_SAPI',
|
||||
'pi' => 'M_PI',
|
||||
],
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
- [CodeQualityStrict](#codequalitystrict) (4)
|
||||
|
||||
- [CodingStyle](#codingstyle) (38)
|
||||
- [CodingStyle](#codingstyle) (37)
|
||||
|
||||
- [Composer](#composer) (5)
|
||||
|
||||
|
@ -136,7 +136,7 @@
|
|||
|
||||
- [SymfonyPhpConfig](#symfonyphpconfig) (1)
|
||||
|
||||
- [Transform](#transform) (34)
|
||||
- [Transform](#transform) (35)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (17)
|
||||
|
||||
|
@ -2268,76 +2268,6 @@ include/require should be followed by absolute path
|
|||
|
||||
<br>
|
||||
|
||||
### FunctionCallToConstantRector
|
||||
|
||||
Changes use of function calls to use constants
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: `Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector`
|
||||
|
||||
```php
|
||||
use Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(FunctionCallToConstantRector::class)
|
||||
->call('configure', [[
|
||||
FunctionCallToConstantRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
'php_sapi_name' => 'PHP_SAPI',
|
||||
],
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- $value = php_sapi_name();
|
||||
+ $value = PHP_SAPI;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
```php
|
||||
use Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(FunctionCallToConstantRector::class)
|
||||
->call('configure', [[
|
||||
FunctionCallToConstantRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
'pi' => 'M_PI',
|
||||
],
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- $value = pi();
|
||||
+ $value = M_PI;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MakeInheritedMethodVisibilitySameAsParentRector
|
||||
|
||||
Make method visibility same as parent one
|
||||
|
@ -2605,7 +2535,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
|
||||
### SplitDoubleAssignRector
|
||||
|
||||
Split multiple inline assigns to `each` own lines default value, to prevent undefined array issues
|
||||
Split multiple inline assigns to each own lines default value, to prevent undefined array issues
|
||||
|
||||
- class: `Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector`
|
||||
|
||||
|
@ -13109,7 +13039,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
|
||||
### PassFactoryToUniqueObjectRector
|
||||
|
||||
Convert new `X/Static::call()` to factories in entities, pass them via constructor to `each` other
|
||||
Convert new `X/Static::call()` to factories in entities, pass them via constructor to each other
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
|
@ -15367,6 +15297,45 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
|
||||
<br>
|
||||
|
||||
### FuncCallToConstFetchRector
|
||||
|
||||
Changes use of function calls to use constants
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: `Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector`
|
||||
|
||||
```php
|
||||
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(FuncCallToConstFetchRector::class)
|
||||
->call('configure', [[
|
||||
FuncCallToConstFetchRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
'php_sapi_name' => 'PHP_SAPI',
|
||||
],
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- $value = php_sapi_name();
|
||||
+ $value = PHP_SAPI;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### FuncCallToMethodCallRector
|
||||
|
||||
Turns defined function calls to local method calls.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Rector\FuncCall;
|
||||
namespace Rector\Transform\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
|
@ -14,9 +14,9 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodingStyle\Tests\Rector\FuncCall\FunctionCallToConstantRector\FunctionCallToConstantRectorTest
|
||||
* @see \Rector\Transform\Tests\Rector\FuncCall\FuncCallToConstFetchRector\FunctionCallToConstantRectorTest
|
||||
*/
|
||||
final class FunctionCallToConstantRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
final class FuncCallToConstFetchRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
@ -58,33 +58,7 @@ CODE_SAMPLE
|
|||
],
|
||||
]
|
||||
),
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$value = pi();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$value = M_PI;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
[
|
||||
self::FUNCTIONS_TO_CONSTANTS => [
|
||||
'pi' => 'M_PI',
|
||||
],
|
||||
]
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\FuncCall\FunctionCallToConstantRector\Fixture;
|
||||
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToConstFetchRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ class Fixture
|
|||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\FuncCall\FunctionCallToConstantRector\Fixture;
|
||||
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToConstFetchRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\FuncCall\FunctionCallToConstantRector;
|
||||
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector;
|
||||
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(FunctionCallToConstantRector::class)
|
||||
$services->set(FuncCallToConstFetchRector::class)
|
||||
->call('configure', [[
|
||||
FunctionCallToConstantRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
FuncCallToConstFetchRector::FUNCTIONS_TO_CONSTANTS => [
|
||||
'php_sapi_name' => 'PHP_SAPI',
|
||||
'pi' => 'M_PI',
|
||||
],
|
Loading…
Reference in New Issue
Block a user