[Naming] Foreach over "data", renames to "datum" (#4221)

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Igor 2020-09-15 10:23:13 +02:00 committed by GitHub
parent 59547a5cbe
commit f2ecdeb0b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
488 changed files with 2155 additions and 1955 deletions

View File

@ -19,23 +19,23 @@ final class AddArgumentTypeWithProbeDataRector extends AbstractArgumentProbeRect
{
return new RectorDefinition('Add argument type based on probed data', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($arg)
{
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(string $arg)
{
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -24,16 +24,16 @@ final class DecorateMethodWithArgumentTypeProbeRector extends AbstractArgumentPr
{
return new RectorDefinition('Add probe that records argument types to each method', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($arg)
{
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($arg)
@ -41,7 +41,7 @@ class SomeClass
\Rector\DynamicTypeAnalysis\Probe\TypeStaticProbe::recordArgumentType($arg, __METHOD__, 0);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -20,7 +20,7 @@ final class RemoveArgumentTypeProbeRector extends AbstractRector
{
return new RectorDefinition('Clean up probe that records argument types', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
use Rector\DynamicTypeAnalysis\Probe\TypeStaticProbe;
class SomeClass
@ -30,16 +30,16 @@ class SomeClass
TypeStaticProbe::recordArgumentType($arg, __METHOD__, 0);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($arg)
{
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -39,7 +39,7 @@ final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends Abstr
'Handles method calls in child of Doctrine EntityRepository and moves them to $this->repository property.',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
<?php
use Doctrine\ORM\EntityRepository;
@ -51,9 +51,9 @@ class SomeRepository extends EntityRepository
return $this->findAll();
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
<?php
use Doctrine\ORM\EntityRepository;
@ -65,7 +65,7 @@ class SomeRepository extends EntityRepository
return $this->repository->findAll();
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -51,7 +51,7 @@ final class ServiceLocatorToDIRector extends AbstractRector
'Turns $this->getRepository() in Symfony Controller to constructor injection and private property access.',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class ProductController extends Controller
{
public function someAction()
@ -60,9 +60,9 @@ class ProductController extends Controller
$entityManager->getRepository('SomethingBundle:Product')->findSomething(...);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class ProductController extends Controller
{
/**
@ -81,7 +81,7 @@ class ProductController extends Controller
$this->productRepository->findSomething(...);
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -25,7 +25,7 @@ final class MoveEntitiesToEntityDirectoryRector extends AbstractFileMovingFileSy
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Move entities to Entity namespace', [new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
// file: app/Controller/Product.php
namespace App\Controller;
@ -38,9 +38,9 @@ use Doctrine\ORM\Mapping as ORM;
class Product
{
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
// file: app/Entity/Product.php
namespace App\Entity;
@ -53,7 +53,7 @@ use Doctrine\ORM\Mapping as ORM;
class Product
{
}
PHP
CODE_SAMPLE
)]);
}

View File

@ -34,7 +34,7 @@ final class MoveInterfacesToContractNamespaceDirectoryRector extends AbstractFil
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Move interface to "Contract" namespace', [new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
// file: app/Exception/Rule.php
namespace App\Exception;
@ -42,9 +42,9 @@ namespace App\Exception;
interface Rule
{
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
// file: app/Contract/Rule.php
namespace App\Contract;
@ -52,7 +52,7 @@ namespace App\Contract;
interface Rule
{
}
PHP
CODE_SAMPLE
)]);
}

View File

@ -36,7 +36,7 @@ final class MoveServicesBySuffixToDirectoryRector extends AbstractFileMovingFile
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Move classes by their suffix to their own group/directory', [new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
// file: app/Entity/ProductRepository.php
namespace App/Entity;
@ -44,9 +44,9 @@ namespace App/Entity;
class ProductRepository
{
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
// file: app/Repository/ProductRepository.php
namespace App/Repository;
@ -54,7 +54,7 @@ namespace App/Repository;
class ProductRepository
{
}
PHP
CODE_SAMPLE
,
[
self::GROUP_NAMES_BY_SUFFIX => ['Repository'],

View File

@ -40,17 +40,17 @@ final class AppUsesStaticCallToUseStatementRector extends AbstractRector
{
return new RectorDefinition('Change App::uses() to use imports', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
App::uses('NotificationListener', 'Event');
CakeEventManager::instance()->attach(new NotificationListener());
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
use Event\NotificationListener;
CakeEventManager::instance()->attach(new NotificationListener());
PHP
CODE_SAMPLE
),
]);
}

View File

@ -47,7 +47,7 @@ final class ArrayToFluentCallRector extends AbstractRector implements Configurab
{
return new RectorDefinition('Moves array options to fluent setter method calls.', [
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
use Cake\ORM\Table;
final class ArticlesTable extends Table
@ -60,9 +60,9 @@ final class ArticlesTable extends Table
]);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
use Cake\ORM\Table;
final class ArticlesTable extends Table
@ -74,7 +74,7 @@ final class ArticlesTable extends Table
->setProperty('person');
}
}
PHP
CODE_SAMPLE
, [
self::ARRAYS_TO_FLUENT_CALLS => [
new ArrayToFluentCall('ArticlesTable', [

View File

@ -39,7 +39,7 @@ final class ModalToGetSetRector extends AbstractRector implements ConfigurableRe
'Changes combined set/get `value()` to specific `getValue()` or `setValue(x)`.',
[
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$object = new InstanceConfigTrait;
$config = $object->config();
@ -47,9 +47,9 @@ $config = $object->config('key');
$object->config('key', 'value');
$object->config(['key' => 'value']);
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
$object = new InstanceConfigTrait;
$config = $object->getConfig();
@ -57,7 +57,7 @@ $config = $object->getConfig('key');
$object->setConfig('key', 'value');
$object->setConfig(['key' => 'value']);
PHP
CODE_SAMPLE
, [
self::UNPREFIXED_METHODS_TO_GET_SET => [
new ModalToGetSet('InstanceConfigTrait', 'config', 'getConfig', 'setConfig'),

View File

@ -38,19 +38,19 @@ final class RenameMethodCallBasedOnParameterRector extends AbstractRector implem
'Changes method calls based on matching the first parameter value.',
[
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$object = new ServerRequest();
$config = $object->getParam('paging');
$object = $object->withParam('paging', ['a value']);
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
$object = new ServerRequest();
$config = $object->getAttribute('paging');
$object = $object->withAttribute('paging', ['a value']);
PHP
CODE_SAMPLE
,
[
self::CALLS_WITH_PARAM_RENAMES => [

View File

@ -36,22 +36,22 @@ final class ImplicitShortClassNameUseStatementRector extends AbstractRector
{
return new RectorDefinition('Collect implicit class names and add imports', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
use App\Foo\Plugin;
class LocationsFixture extends TestFixture implements Plugin
{
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
use App\Foo\Plugin;
use Cake\TestSuite\Fixture\TestFixture;
class LocationsFixture extends TestFixture implements Plugin
{
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -25,7 +25,7 @@ final class ChangeSnakedFixtureNameToPascalRector extends AbstractRector
{
return new RectorDefinition('Changes $fixtues style from snake_case to PascalCase.', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeTest
{
protected $fixtures = [
@ -33,9 +33,9 @@ class SomeTest
'app.users',
'some_plugin.posts/special_posts',
];
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeTest
{
protected $fixtures = [
@ -43,7 +43,7 @@ class SomeTest
'app.Users',
'some_plugin.Posts/SpecialPosts',
];
PHP
CODE_SAMPLE
),
]);
}

View File

@ -37,7 +37,7 @@ final class ArrayThisCallToThisMethodCallRector extends AbstractRector
{
return new RectorDefinition('Change `[$this, someMethod]` without any args to $this->someMethod()', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -50,9 +50,9 @@ class SomeClass
return 'more';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -65,7 +65,7 @@ class SomeClass
return 'more';
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -41,7 +41,7 @@ final class CallableThisArrayToAnonymousFunctionRector extends AbstractRector
{
return new RectorDefinition('Convert [$this, "method"] to proper anonymous function', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -57,9 +57,9 @@ class SomeClass
return $first <=> $second;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -77,7 +77,7 @@ class SomeClass
return $first <=> $second;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -23,7 +23,7 @@ final class SplitListAssignToSeparateLineRector extends AbstractRector
{
return new RectorDefinition('Splits `[$a, $b] = [5, 10]` scalar assign to standalone lines', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(): void
@ -31,9 +31,9 @@ final class SomeClass
[$a, $b] = [1, 2];
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(): void
@ -42,7 +42,7 @@ final class SomeClass
$b = 2;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -34,21 +34,21 @@ final class SimplifyDeMorganBinaryRector extends AbstractRector
{
return new RectorDefinition('Simplify negated conditions with de Morgan theorem', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
<?php
$a = 5;
$b = 10;
$result = !($a > 20 || $b <= 50);
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
<?php
$a = 5;
$b = 10;
$result = $a <= 20 && $b > 50;
PHP
CODE_SAMPLE
),
]);
}

View File

@ -40,7 +40,7 @@ final class ThrowWithPreviousExceptionRector extends AbstractRector
'When throwing into a catch block, checks that the previous exception is passed to the new throw clause',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -52,9 +52,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -66,7 +66,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -50,7 +50,7 @@ final class CompleteDynamicPropertiesRector extends AbstractRector
{
return new RectorDefinition('Add missing dynamic properties', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function set()
@ -58,9 +58,9 @@ class SomeClass
$this->value = 5;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
/**
@ -72,7 +72,7 @@ class SomeClass
$this->value = 5;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -32,7 +32,7 @@ final class JoinStringConcatRector extends AbstractRector
{
return new RectorDefinition('Joins concat of 2 strings, unless the lenght is too long', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -40,9 +40,9 @@ class SomeClass
$name = 'Hi' . ' Tom';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -50,7 +50,7 @@ class SomeClass
$name = 'Hi Tom';
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -24,7 +24,7 @@ final class UseIdenticalOverEqualWithSameTypeRector extends AbstractRector
{
return new RectorDefinition('Use ===/!== over ==/!=, it values have the same type', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(int $firstValue, int $secondValue)
@ -33,9 +33,9 @@ class SomeClass
$isDiffernt = $firstValue != $secondValue;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(int $firstValue, int $secondValue)
@ -44,7 +44,7 @@ class SomeClass
$isDiffernt = $firstValue !== $secondValue;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -25,7 +25,7 @@ final class InlineIfToExplicitIfRector extends AbstractRector
{
return new RectorDefinition('Change inline if to explicit if', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -35,9 +35,9 @@ class SomeClass
is_null($userId) && $userId = 5;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -49,7 +49,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -34,7 +34,7 @@ final class ForRepeatedCountToOwnVariableRector extends AbstractRector
{
return new RectorDefinition('Change count() in for function to own variable', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($items)
@ -44,9 +44,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($items)
@ -57,7 +57,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -65,7 +65,7 @@ final class ForToForeachRector extends AbstractRector
{
return new RectorDefinition('Change for() to foreach() where useful', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($tokens)
@ -81,9 +81,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($tokens)
@ -99,7 +99,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -35,7 +35,7 @@ final class ForeachItemsAssignToEmptyArrayToAssignRector extends AbstractRector
{
return new RectorDefinition('Change foreach() items assign to empty array to direct assign', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($items)
@ -46,9 +46,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($items)
@ -57,7 +57,7 @@ class SomeClass
$items2 = $items;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -51,7 +51,7 @@ final class ForeachToInArrayRector extends AbstractRector
'Simplify `foreach` loops into `in_array` when possible',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
foreach ($items as $item) {
if ($item === 'something') {
return true;
@ -59,7 +59,7 @@ foreach ($items as $item) {
}
return false;
PHP
CODE_SAMPLE
,
'in_array("something", $items, true);'
),

View File

@ -27,7 +27,7 @@ final class SimplifyForeachToArrayFilterRector extends AbstractRector
{
return new RectorDefinition('Simplify foreach with function filtering to array filter', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$directories = [];
$possibleDirectories = [];
foreach ($possibleDirectories as $possibleDirectory) {
@ -35,12 +35,12 @@ foreach ($possibleDirectories as $possibleDirectory) {
$directories[] = $possibleDirectory;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
$possibleDirectories = [];
$directories = array_filter($possibleDirectories, 'file_exists');
PHP
CODE_SAMPLE
),
]);
}

View File

@ -46,7 +46,7 @@ final class SimplifyForeachToCoalescingRector extends AbstractRector
{
return new RectorDefinition('Changes foreach that returns set value to ??', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
if ($currentFunction === $oldFunction) {
return $newFunction;
@ -54,11 +54,11 @@ foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
}
return null;
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
return $this->oldToNewFunctions[$currentFunction] ?? null;
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class UnusedForeachValueToArrayKeysRector extends AbstractRector
{
return new RectorDefinition('Change foreach with unused $value but only $key, to array_keys()', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -32,9 +32,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -45,7 +45,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -30,13 +30,13 @@ final class AddPregQuoteDelimiterRector extends AbstractRector
{
return new RectorDefinition('Add preg_quote delimiter when missing', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
'#' . preg_quote('name') . '#';
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
'#' . preg_quote('name', '#') . '#';
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class ArrayKeysAndInArrayToArrayKeyExistsRector extends AbstractRector
{
return new RectorDefinition('Replace array_keys() and in_array() to array_key_exists()', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($packageName, $values)
@ -31,9 +31,9 @@ class SomeClass
return in_array($packageName, $keys, true);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($packageName, $values)
@ -41,7 +41,7 @@ class SomeClass
return array_key_exists($packageName, $values);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -25,7 +25,7 @@ final class ArrayMergeOfNonArraysToSimpleArrayRector extends AbstractRector
{
return new RectorDefinition('Change array_merge of non arrays to array directly', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function go()
@ -36,9 +36,9 @@ class SomeClass
return array_merge([$value], [$value2]);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function go()
@ -49,7 +49,7 @@ class SomeClass
return [$value, $value2];
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -26,7 +26,7 @@ final class ChangeArrayPushToArrayAssignRector extends AbstractRector
{
return new RectorDefinition('Change array_push() to direct variable assign', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -35,9 +35,9 @@ class SomeClass
array_push($items, $item);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -46,7 +46,7 @@ class SomeClass
$items[] = $item;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -32,7 +32,7 @@ final class CompactToVariablesRector extends AbstractRector
{
return new RectorDefinition('Change compact() call to own array', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -43,9 +43,9 @@ class SomeClass
return compact('checkout', 'form');
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -56,7 +56,7 @@ class SomeClass
return ['checkout' => $checkout, 'form' => $form];
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -23,7 +23,7 @@ final class IntvalToTypeCastRector extends AbstractRector
{
return new RectorDefinition('Change intval() to faster and readable (int) $value', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -31,9 +31,9 @@ class SomeClass
return intval($value);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -41,7 +41,7 @@ class SomeClass
return (int) $value;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class IsAWithStringWithThirdArgumentRector extends AbstractRector
{
return new RectorDefinition('Complete missing 3rd argument in case is_a() function in case of strings', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(string $value)
@ -29,9 +29,9 @@ class SomeClass
return is_a($value, 'stdClass');
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(string $value)
@ -39,7 +39,7 @@ class SomeClass
return is_a($value, 'stdClass', true);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class RemoveSoleValueSprintfRector extends AbstractRector
{
return new RectorDefinition('Remove sprintf() wrapper if not needed', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -32,9 +32,9 @@ class SomeClass
$value = sprintf('%s', $welcome);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -45,7 +45,7 @@ class SomeClass
$value = $welcome;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -47,7 +47,7 @@ final class SetTypeToCastRector extends AbstractRector
{
return new RectorDefinition('Changes settype() to (type) where possible', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($foo)
@ -57,9 +57,9 @@ class SomeClass
return settype($foo, 'integer');
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(array $items)
@ -69,7 +69,7 @@ class SomeClass
return (int) $foo;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -46,7 +46,7 @@ final class SimplifyRegexPatternRector extends AbstractRector
{
return new RectorDefinition('Simplify regex pattern to known ranges', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -54,9 +54,9 @@ class SomeClass
preg_match('#[a-zA-Z0-9+]#', $value);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -64,7 +64,7 @@ class SomeClass
preg_match('#[\w\d+]#', $value);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class SingleInArrayToCompareRector extends AbstractRector
{
return new RectorDefinition('Changes in_array() with single element to ===', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -32,9 +32,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -44,7 +44,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -53,7 +53,7 @@ final class RemoveAlwaysTrueConditionSetInConstructorRector extends AbstractRect
{
return new RectorDefinition('If conditions is always true, perform the content right away', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
private $value;
@ -70,9 +70,9 @@ final class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
private $value;
@ -87,7 +87,7 @@ final class SomeClass
return 'yes';
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -25,7 +25,7 @@ final class BooleanNotIdenticalToNotIdenticalRector extends AbstractRector
'Negated identical boolean compare to not identical compare (does not apply to non-bool values)',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -38,9 +38,9 @@ class SomeClass
var_dump($a !== $b); // true
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -53,7 +53,7 @@ class SomeClass
var_dump($a !== $b); // true
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -23,7 +23,7 @@ final class SimplifyBoolIdenticalTrueRector extends AbstractRector
{
return new RectorDefinition('Symplify bool value compare to true or false', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(bool $value, string $items)
@ -32,9 +32,9 @@ class SomeClass
$match = in_array($value, $items, TRUE) !== FALSE;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(bool $value, string $items)
@ -43,7 +43,7 @@ class SomeClass
$match = in_array($value, $items, TRUE);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class StrlenZeroToIdenticalEmptyStringRector extends AbstractRector
{
return new RectorDefinition('Changes strlen comparison to 0 to direct empty string compare', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -30,9 +30,9 @@ class SomeClass
$empty = strlen($value) === 0;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -40,7 +40,7 @@ class SomeClass
$empty = $value === '';
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class CombineIfRector extends AbstractRector
{
return new RectorDefinition('Merges nested if statements', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -33,9 +33,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -45,7 +45,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -45,7 +45,7 @@ final class ConsecutiveNullCompareReturnsToNullCoalesceQueueRector extends Abstr
{
return new RectorDefinition('Change multiple null compares to ?? queue', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -61,9 +61,9 @@ class SomeClass
return null;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -71,7 +71,7 @@ class SomeClass
return $this->orderItem ?? $this->orderItemUnit;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -37,7 +37,7 @@ final class ExplicitBoolCompareRector extends AbstractRector
{
return new RectorDefinition('Make if conditions more explicit', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeController
{
public function run($items)
@ -47,9 +47,9 @@ final class SomeController
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeController
{
public function run($items)
@ -59,7 +59,7 @@ final class SomeController
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -20,7 +20,7 @@ final class ShortenElseIfRector extends AbstractRector
{
return new RectorDefinition('Shortens else/if to elseif', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -34,9 +34,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -48,7 +48,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -30,7 +30,7 @@ final class SimplifyIfElseToTernaryRector extends AbstractRector
{
return new RectorDefinition('Changes if/else for same value as assign to ternary', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -42,9 +42,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -52,7 +52,7 @@ class SomeClass
$this->arrayBuilt[][$key] = empty($value) ? true : $value;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -28,7 +28,7 @@ final class SimplifyIfIssetToNullCoalescingRector extends AbstractRector
{
return new RectorDefinition('Simplify binary if to null coalesce', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeController
{
public function run($possibleStatieYamlFile)
@ -40,9 +40,9 @@ final class SomeController
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeController
{
public function run($possibleStatieYamlFile)
@ -50,7 +50,7 @@ final class SomeController
$possibleStatieYamlFile['import'] = array_merge($possibleStatieYamlFile['import'] ?? [], $filesToImport);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -32,19 +32,19 @@ final class SimplifyIfNotNullReturnRector extends AbstractRector
{
return new RectorDefinition('Changes redundant null check to instant return', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$newNode = 'something ;
if ($newNode !== null) {
return $newNode;
}
return null;
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
$newNode = 'something ;
return $newNode;
PHP
CODE_SAMPLE
),
]);
}

View File

@ -59,13 +59,13 @@ final class SimplifyIfReturnBoolRector extends AbstractRector
{
return new RectorDefinition('Shortens if return false/true to direct return', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
if (strpos($docToken->getContent(), "\n") === false) {
return true;
}
return false;
PHP
CODE_SAMPLE
,
'return strpos($docToken->getContent(), "\n") === false;'
),

View File

@ -27,7 +27,7 @@ final class AbsolutizeRequireAndIncludePathRector extends AbstractRector
'include/require to absolute path. This Rector might introduce backwards incompatible code, when the include/require beeing changed depends on the current working directory.',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -37,9 +37,9 @@ class SomeClass
require $variable;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -49,7 +49,7 @@ class SomeClass
require $variable;
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -23,7 +23,7 @@ final class AndAssignsToSeparateLinesRector extends AbstractRector
{
return new RectorDefinition('Split 2 assigns ands to separate line', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -32,9 +32,9 @@ class SomeClass
$token = 4 and $tokens[] = $token;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -44,7 +44,7 @@ class SomeClass
$tokens[] = $token;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -24,17 +24,17 @@ final class LogicalToBooleanRector extends AbstractRector
{
return new RectorDefinition('Change OR, AND to ||, && with more common understanding', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
if ($f = false or true) {
return $f;
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
if (($f = false) || true) {
return $f;
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -38,7 +38,7 @@ final class FixClassCaseSensitivityNameRector extends AbstractRector
{
return new RectorDefinition('Change miss-typed case sensitivity name to correct one', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run()
@ -50,9 +50,9 @@ final class SomeClass
final class AnotherClass
{
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run()
@ -64,7 +64,7 @@ final class SomeClass
final class AnotherClass
{
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class CommonNotEqualRector extends AbstractRector
{
return new RectorDefinition('Use common != instead of less known <> with same meaning', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run($one, $two)
@ -29,9 +29,9 @@ final class SomeClass
return $one <> $two;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run($one, $two)
@ -39,7 +39,7 @@ final class SomeClass
return $one != $two;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -38,18 +38,18 @@ final class SimplifyUselessVariableRector extends AbstractRector
{
return new RectorDefinition('Removes useless variable assigns', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
function () {
$a = true;
return $a;
};
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
function () {
return true;
};
PHP
CODE_SAMPLE
),
]);
}

View File

@ -24,7 +24,7 @@ final class ArrayKeyExistsTernaryThenValueToCoalescingRector extends AbstractRec
{
return new RectorDefinition('Change array_key_exists() ternary to coalesing', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($values, $keyToMatch)
@ -32,9 +32,9 @@ class SomeClass
$result = array_key_exists($keyToMatch, $values) ? $values[$keyToMatch] : null;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($values, $keyToMatch)
@ -42,7 +42,7 @@ class SomeClass
$result = $values[$keyToMatch] ?? null;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -20,7 +20,7 @@ final class SimplifyDuplicatedTernaryRector extends AbstractRector
{
return new RectorDefinition('Remove ternary that duplicated return value of true : false', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(bool $value, string $name)
@ -29,9 +29,9 @@ class SomeClass
$isName = $name ? true : false;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(bool $value, string $name)
@ -40,7 +40,7 @@ class SomeClass
$isName = $name ? true : false;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -53,7 +53,7 @@ final class ManualJsonStringToJsonEncodeArrayRector extends AbstractRector
{
return new RectorDefinition('Add extra space before new assign set', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run()
@ -61,9 +61,9 @@ final class SomeClass
$someJsonAsString = '{"role_name":"admin","numberz":{"id":"10"}}';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run()
@ -76,7 +76,7 @@ final class SomeClass
$someJsonAsString = Nette\Utils\Json::encode($data);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class SplitDoubleAssignRector extends AbstractRector
'Split multiple inline assigns to each own lines default value, to prevent undefined array issues',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -29,9 +29,9 @@ class SomeClass
$one = $two = 1;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -40,7 +40,7 @@ class SomeClass
$two = 1;
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -26,7 +26,7 @@ final class CatchExceptionNameMatchingTypeRector extends AbstractRector
{
return new RectorDefinition('Type and name of catch exception should match', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -38,9 +38,9 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -52,7 +52,7 @@ class SomeClass
}
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class SplitGroupedConstantsAndPropertiesRector extends AbstractRector
{
return new RectorDefinition('Separate constant and properties to own lines', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
const HI = true, AHOJ = 'true';
@ -32,9 +32,9 @@ class SomeClass
*/
public $isIt, $isIsThough;
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
const HI = true;
@ -50,7 +50,7 @@ class SomeClass
*/
public $isIsThough;
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -29,14 +29,14 @@ final class VarConstantCommentRector extends AbstractRector
{
return new RectorDefinition('Constant should have a @var comment with type', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
const HI = 'hi';
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
/**
@ -44,7 +44,7 @@ class SomeClass
*/
const HI = 'hi';
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -28,7 +28,7 @@ final class MakeInheritedMethodVisibilitySameAsParentRector extends AbstractRect
{
return new RectorDefinition('Make method visibility same as parent one', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class ChildClass extends ParentClass
{
public function run()
@ -42,9 +42,9 @@ class ParentClass
{
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class ChildClass extends ParentClass
{
protected function run()
@ -58,7 +58,7 @@ class ParentClass
{
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -36,7 +36,7 @@ final class NewlineBeforeNewAssignSetRector extends AbstractRector
{
return new RectorDefinition('Add extra space before new assign set', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run()
@ -47,9 +47,9 @@ final class SomeClass
$value2->setValue(1);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run()
@ -61,7 +61,7 @@ final class SomeClass
$value2->setValue(1);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -73,7 +73,7 @@ final class ReturnArrayClassMethodToYieldRector extends AbstractRector implement
{
return new RectorDefinition('Turns array return to yield return in specific type and method', [
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
@ -81,9 +81,9 @@ class SomeEventSubscriber implements EventSubscriberInterface
return ['event' => 'callback'];
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
@ -91,7 +91,7 @@ class SomeEventSubscriber implements EventSubscriberInterface
yield 'event' => 'callback';
}
}
PHP
CODE_SAMPLE
,
[
self::METHODS_TO_YIELDS => [

View File

@ -52,7 +52,7 @@ final class YieldClassMethodToArrayClassMethodRector extends AbstractRector impl
{
return new RectorDefinition('Turns yield return to array return in specific type and method', [
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
@ -60,9 +60,9 @@ class SomeEventSubscriber implements EventSubscriberInterface
yield 'event' => 'callback';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
@ -70,7 +70,7 @@ class SomeEventSubscriber implements EventSubscriberInterface
return ['event' => 'callback'];
}
}
PHP
CODE_SAMPLE
,
[
self::METHODS_BY_TYPE => [

View File

@ -45,7 +45,7 @@ final class AddArrayDefaultToArrayPropertyRector extends AbstractRector
{
return new RectorDefinition('Adds array default value to property to prevent foreach over null error', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
/**
@ -58,9 +58,9 @@ class SomeClass
return $this->values === null;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
/**
@ -73,7 +73,7 @@ class SomeClass
return $this->values === [];
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -39,7 +39,7 @@ final class EncapsedStringsToSprintfRector extends AbstractRector
{
return new RectorDefinition('Convert enscaped {$string} to more readable sprintf', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(string $format)
@ -47,9 +47,9 @@ final class SomeClass
return "Unsupported format {$format}";
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(string $format)
@ -57,7 +57,7 @@ final class SomeClass
return sprintf('Unsupported format %s', $format);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,19 +21,19 @@ final class WrapEncapsedVariableInCurlyBracesRector extends AbstractRector
{
return new RectorDefinition('Wrap encapsed variables in curly braces', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
function run($world)
{
echo "Hello $world!"
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
function run($world)
{
echo "Hello {$world}!"
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class CallUserFuncCallToVariadicRector extends AbstractRector
{
return new RectorDefinition('Replace call_user_func_call with variadic', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -30,9 +30,9 @@ class SomeClass
call_user_func_array('some_function', $items);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -40,7 +40,7 @@ class SomeClass
some_function(...$items);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -23,7 +23,7 @@ final class ConsistentImplodeRector extends AbstractRector
{
return new RectorDefinition('Changes various implode forms to consistent one', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(array $items)
@ -34,9 +34,9 @@ class SomeClass
$itemsAsStrings = implode('|', $items);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(array $items)
@ -47,7 +47,7 @@ class SomeClass
$itemsAsStrings = implode('|', $items);
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -69,7 +69,7 @@ final class ConsistentPregDelimiterRector extends AbstractRector implements Conf
{
return new RectorDefinition('Replace PREG delimiter with configured one', [
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -78,9 +78,9 @@ class SomeClass
preg_match_all('~value~im', $value);
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -89,7 +89,7 @@ class SomeClass
preg_match_all('#value#im', $value);
}
}
PHP
CODE_SAMPLE
,
[
self::DELIMITER => '#',

View File

@ -24,21 +24,21 @@ final class CamelCaseFunctionNamingToUnderscoreRector extends AbstractRector
{
return new RectorDefinition('Change CamelCase naming of functions to under_score naming', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
function someCamelCaseFunction()
{
}
someCamelCaseFunction();
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
function some_camel_case_function()
{
}
some_camel_case_function();
PHP
CODE_SAMPLE
),
]);
}

View File

@ -32,23 +32,23 @@ final class NullableCompareToNullRector extends AbstractRector
'Changes negate of empty comparison of nullable value to explicit === or !== compare',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
/** @var stdClass|null $value */
if ($value) {
}
if (!$value) {
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
/** @var stdClass|null $value */
if ($value !== null) {
}
if ($value === null) {
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -23,7 +23,7 @@ final class FollowRequireByDirRector extends AbstractRector
{
return new RectorDefinition('include/require should be followed by absolute path', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -31,9 +31,9 @@ class SomeClass
require 'autoload.php';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -41,7 +41,7 @@ class SomeClass
require __DIR__ . '/autoload.php';
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -44,7 +44,7 @@ final class PreferThisOrSelfMethodCallRector extends AbstractRector implements C
{
return new RectorDefinition('Changes $this->... to self:: or vise versa for specific types', [
new ConfiguredCodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass extends PHPUnit\TestCase
{
public function run()
@ -52,9 +52,9 @@ class SomeClass extends PHPUnit\TestCase
$this->assertThis();
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass extends PHPUnit\TestCase
{
public function run()
@ -62,7 +62,7 @@ class SomeClass extends PHPUnit\TestCase
self::assertThis();
}
}
PHP
CODE_SAMPLE
,
[
self::TYPE_TO_PREFERENCE => [

View File

@ -23,7 +23,7 @@ final class UseMessageVariableForSprintfInSymfonyStyleRector extends AbstractRec
'Decouple $message property from sprintf() calls in $this->smyfonyStyle->method()',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
use Symfony\Component\Console\Style\SymfonyStyle;
final class SomeClass
@ -33,9 +33,9 @@ final class SomeClass
$symfonyStyle->info(sprintf('Hi %s', 'Tom'));
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
use Symfony\Component\Console\Style\SymfonyStyle;
final class SomeClass
@ -46,7 +46,7 @@ final class SomeClass
$symfonyStyle->info($message);
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -25,7 +25,7 @@ final class UseIncrementAssignRector extends AbstractRector
'Use ++ increment instead of `$var += 1`',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -33,9 +33,9 @@ class SomeClass
$style += 1;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -43,7 +43,7 @@ class SomeClass
++$style
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -25,7 +25,7 @@ final class UnderscoreToCamelCasePropertyNameRector extends AbstractRector
{
return new RectorDefinition('Change under_score names to camelCase', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public $property_name;
@ -35,9 +35,9 @@ final class SomeClass
$this->property_name = 5;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public $propertyName;
@ -47,7 +47,7 @@ final class SomeClass
$this->propertyName = 5;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class SplitStringClassConstantToClassConstFetchRector extends AbstractRect
{
return new RectorDefinition('Separate class constant in a string to class constant fetch and string', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
const HI = true;
@ -35,9 +35,9 @@ class AnotherClass
return 'SomeClass::HI';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
const HI = true;
@ -50,7 +50,7 @@ class AnotherClass
return SomeClass::class . '::HI';
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,7 +21,7 @@ final class SymplifyQuoteEscapeRector extends AbstractRector
{
return new RectorDefinition('Prefer quote that are not inside the string', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -30,9 +30,9 @@ class SomeClass
$name = '\' Sara';
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -41,7 +41,7 @@ class SomeClass
$name = "' Sara";
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -24,13 +24,13 @@ final class UseClassKeywordForClassNameResolutionRector extends AbstractRector
'Use `class` keyword for class name resolution in string instead of hardcoded string reference',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$value = 'App\SomeClass::someMethod()';
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
$value = \App\SomeClass . '::someMethod()';
PHP
CODE_SAMPLE
),
]
);

View File

@ -27,7 +27,7 @@ final class BinarySwitchToIfElseRector extends AbstractRector
{
return new RectorDefinition('Changes switch with 2 options to if-else', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
switch ($foo) {
case 'my string':
$result = 'ok';
@ -36,15 +36,15 @@ switch ($foo) {
default:
$result = 'not ok';
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
if ($foo == 'my string') {
$result = 'ok;
} else {
$result = 'not ok';
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,19 +22,19 @@ final class TernaryConditionVariableAssignmentRector extends AbstractRector
{
return new RectorDefinition('Assign outcome of ternary condition to variable, where applicable', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
function ternary($value)
{
$value ? $a = 1 : $a = 0;
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
function ternary($value)
{
$a = $value ? 1 : 0;
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -80,7 +80,7 @@ final class AnnotateThrowablesRector extends AbstractRector
'Adds @throws DocBlock comments to methods that thrwo \Throwables.', [
new CodeSample(
// code before
<<<'PHP'
<<<'CODE_SAMPLE'
class RootExceptionInMethodWithDocblock
{
/**
@ -93,10 +93,10 @@ class RootExceptionInMethodWithDocblock
throw new \RuntimeException('', $code);
}
}
PHP
CODE_SAMPLE
,
// code after
<<<'PHP'
<<<'CODE_SAMPLE'
class RootExceptionInMethodWithDocblock
{
/**
@ -110,7 +110,7 @@ class RootExceptionInMethodWithDocblock
throw new \RuntimeException('', $code);
}
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -76,21 +76,21 @@ final class RemoveUnusedAliasRector extends AbstractRector
'Removes unused use aliases. Keep annotation aliases like "Doctrine\ORM\Mapping as ORM" to keep convention format',
[
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
use Symfony\Kernel as BaseKernel;
class SomeClass extends BaseKernel
{
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
use Symfony\Kernel;
class SomeClass extends Kernel
{
}
PHP
CODE_SAMPLE
),
]
);

View File

@ -22,16 +22,16 @@ final class SplitGroupedUseImportsRector extends AbstractRector
{
return new RectorDefinition('Split grouped use imports and trait statements to standalone lines', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
use A, B;
class SomeClass
{
use SomeTrait, AnotherTrait;
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
use A;
use B;
@ -40,7 +40,7 @@ class SomeClass
use SomeTrait;
use AnotherTrait;
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -32,7 +32,7 @@ final class UnderscoreToCamelCaseVariableNameRector extends AbstractRector
{
return new RectorDefinition('Change under_score names to camelCase', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run($a_b)
@ -40,9 +40,9 @@ final class SomeClass
$some_value = $a_b;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run($aB)
@ -50,7 +50,7 @@ final class SomeClass
$someValue = $aB;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -21,18 +21,18 @@ final class RemoveDuplicatedArrayKeyRector extends AbstractRector
{
return new RectorDefinition('Remove duplicated key in defined arrays.', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$item = [
1 => 'A',
1 => 'B'
];
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
$item = [
1 => 'B'
];
PHP
CODE_SAMPLE
),
]);
}

View File

@ -23,7 +23,7 @@ final class RemoveAssignOfVoidReturnFunctionRector extends AbstractRector
{
return new RectorDefinition('Remove assign of void function/method to variable', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -35,9 +35,9 @@ class SomeClass
{
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -49,7 +49,7 @@ class SomeClass
{
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -38,10 +38,10 @@ final class RemoveDoubleAssignRector extends AbstractRector
{
return new RectorDefinition('Simplify useless double assigns', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
$value = 1;
$value = 1;
PHP
CODE_SAMPLE
,
'$value = 1;'
),

View File

@ -22,7 +22,7 @@ final class RemoveUnusedVariableAssignRector extends AbstractRector
{
return new RectorDefinition('Remove unused assigns to variables', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -30,16 +30,16 @@ class SomeClass
$value = 5;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -27,7 +27,7 @@ final class RemoveDuplicatedInstanceOfRector extends AbstractRector
{
return new RectorDefinition('Remove duplicated instanceof in one call', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
@ -36,9 +36,9 @@ class SomeClass
$isIt = $value instanceof A && $value instanceof A;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value): void
@ -47,7 +47,7 @@ class SomeClass
$isIt = $value instanceof A;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -19,7 +19,7 @@ final class RemoveAndTrueRector extends AbstractRector
{
return new RectorDefinition('Remove and true that has no added value', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -27,9 +27,9 @@ class SomeClass
return true && 5 === 1;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
@ -37,7 +37,7 @@ class SomeClass
return 5 === 1;
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -22,7 +22,7 @@ final class RemoveUnusedClassConstantRector extends AbstractRector implements Ze
{
return new RectorDefinition('Remove unused class constants', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
private const SOME_CONST = 'dead';
@ -31,16 +31,16 @@ class SomeClass
{
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
}
}
PHP
CODE_SAMPLE
),
]);
}

View File

@ -30,7 +30,7 @@ final class RemoveUnusedPrivateConstantRector extends AbstractRector
{
return new RectorDefinition('Remove unused private constant', [
new CodeSample(
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeController
{
private const SOME_CONSTANT = 5;
@ -39,9 +39,9 @@ final class SomeController
return 5;
}
}
PHP
CODE_SAMPLE
,
<<<'PHP'
<<<'CODE_SAMPLE'
final class SomeController
{
public function run()
@ -49,7 +49,7 @@ final class SomeController
return 5;
}
}
PHP
CODE_SAMPLE
),
]);
}

Some files were not shown because too many files have changed in this diff Show More