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
74 changes: 73 additions & 1 deletion docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# All 370 Rectors Overview
# All 373 Rectors Overview

- [Projects](#projects)
- [General](#general)
Expand Down Expand Up @@ -45,6 +45,7 @@
- [Sensio](#sensio)
- [Shopware](#shopware)
- [Silverstripe](#silverstripe)
- [StrictCodeQuality](#strictcodequality)
- [Sylius](#sylius)
- [Symfony](#symfony)
- [SymfonyCodeQuality](#symfonycodequality)
Expand Down Expand Up @@ -1241,6 +1242,36 @@ include/require should be followed by absolute path

<br>

### `FunctionCallToConstantRector`

- class: `Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector`

Changes use of function calls to use constants

```diff
class SomeClass
{
public function run()
{
- $value = php_sapi_name();
+ $value = PHP_SAPI;
}
}
```

```diff
class SomeClass
{
public function run()
{
- $value = pi();
+ $value = M_PI;
}
}
```

<br>

### `IdenticalFalseToBooleanNotRector`

- class: `Rector\CodingStyle\Rector\Identical\IdenticalFalseToBooleanNotRector`
Expand Down Expand Up @@ -1629,6 +1660,25 @@ Constant should have a @var comment with type

<br>

### `VersionCompareFuncCallToConstantRector`

- class: `Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector`

Changes use of call to version compare function to use of PHP version constant

```diff
class SomeClass
{
public function run()
{
- version_compare(PHP_VERSION, '5.3.0', '<');
+ PHP_VERSION_ID < 50300;
}
}
```

<br>

### `YieldClassMethodToArrayClassMethodRector`

- class: `Rector\CodingStyle\Rector\ClassMethod\YieldClassMethodToArrayClassMethodRector`
Expand Down Expand Up @@ -5940,6 +5990,28 @@ Turns defined function call to static method call.

<br>

## StrictCodeQuality

### `VarInlineAnnotationToAssertRector`

- class: `Rector\StrictCodeQuality\Rector\Stmt\VarInlineAnnotationToAssertRector`

Turn @var inline checks above code to assert() of hte type

```diff
class SomeClass
{
public function run()
{
/** @var SpecificClass $value */
+ assert($value instanceof SpecificClass);
$value->call();
}
}
```

<br>

## Sylius

### `ReplaceCreateMethodWithoutReviewerRector`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ private function processGroupNamesBySuffix(
}

// is suffix in the same category, e.g. "Exception/SomeException.php"
$expectedLocationFilePattern = sprintf('#\/%s\/.+%s#', preg_quote($groupName), preg_quote($suffixPattern));
$expectedLocationFilePattern = sprintf(
'#\/%s\/.+%s#',
preg_quote($groupName, '#'),
preg_quote($suffixPattern, '#')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

);
if (Strings::match($smartFileInfo->getRealPath(), $expectedLocationFilePattern)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function isTagMatchToNodeAndClass(string $tag, Node $node, string $matchi
private function isUseMatchingName(string $tag, UseUse $useUse): bool
{
$shortName = $useUse->alias ? $useUse->alias->name : $useUse->name->getLast();
$shortNamePattern = preg_quote($shortName);
$shortNamePattern = preg_quote($shortName, '#');

return (bool) Strings::match($tag, '#' . $shortNamePattern . '(\\\\[\w]+)?#i');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,22 @@ private function detectOldWhitespaces(Node $node, array $tokens, StartEndValueOb
}
}

$oldWhitespaces[] = $value;
$oldWhitespaces[] = [$value];
}

// quoted string with spaces?
if ($this->isQuotedStringWithSpaces($tokens, $i)) {
$matches = Strings::matchAll($tokens[$i][0], '#\s+#m');
if ($matches !== []) {
$oldWhitespaces = array_merge($oldWhitespaces, Arrays::flatten($matches));
$oldWhitespaces[] = Arrays::flatten($matches);
}
}
}

if ($oldWhitespaces !== []) {
$oldWhitespaces = array_merge([], ...$oldWhitespaces);
}

return $oldWhitespaces;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ private function filterOutInterfaceRequiredMethods(Class_ $class, array $unusedM

$interfaceMethods = [];
foreach ($interfaces as $interface) {
$interfaceMethods = array_merge($interfaceMethods, get_class_methods($interface));
$interfaceMethods[] = get_class_methods($interface);
}

if ($interfaceMethods !== []) {
$interfaceMethods = array_merge([], ...$interfaceMethods);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather confusing, same variable is used for different array nesting

}

return array_diff($unusedMethods, $interfaceMethods);
Expand Down
9 changes: 5 additions & 4 deletions packages/NodeTypeResolver/src/NodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,14 @@ private function unionWithParentClassesInterfacesAndUsedTraits(Type $type): Type

$classReflection = $this->broker->getClass($unionedType->getClassName());

$allTypes = array_merge(
$allTypes,
$this->classReflectionTypesResolver->resolve($classReflection)
);
$allTypes[] = $this->classReflectionTypesResolver->resolve($classReflection);
}
}

if ($allTypes !== []) {
$allTypes = array_merge([], ...$allTypes);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


return $this->typeFactory->createObjectTypeOrUnionType($allTypes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ private function isCurrentNamespaceSameShortClassAlreadyUsed(
// short with space " Type"| fqn
$shortNameOrFullyQualifiedNamePattern = sprintf(
'#(\s%s\b|\b%s\b)#',
preg_quote($shortenedObjectType->getShortName()),
preg_quote($fullyQualifiedName)
preg_quote($shortenedObjectType->getShortName(), '#'),
preg_quote($fullyQualifiedName, '#')
);

$isShortClassUsed = (bool) Strings::match($printedClass, $shortNameOrFullyQualifiedNamePattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function provide(): array
}

$sectionDirectories = $this->collectDirectoriesFromAutoload($composerJson[$autoloadSection]);
$autoloadDirectories = array_merge($autoloadDirectories, $sectionDirectories);
$autoloadDirectories[] = $sectionDirectories;
}

if ($autoloadDirectories !== []) {
$autoloadDirectories = array_merge([], ...$autoloadDirectories);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


return $autoloadDirectories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function refactor(Node $node): ?Node

$dataProviderClassMethods = $this->createDataProviderClassMethodsFromRecipes();

$node->stmts = array_Merge($node->stmts, $dataProviderClassMethods);
$node->stmts = array_merge($node->stmts, $dataProviderClassMethods);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


return $node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function processExceptionMessageContains(MethodCall $methodCall, Variabl
if ($methodCall->args[0]->value instanceof String_) {
/** @var String_ $oldString */
$oldString = $methodCall->args[0]->value;
$methodCall->args[0]->value = new String_('#' . preg_quote($oldString->value) . '#');
$methodCall->args[0]->value = new String_('#' . preg_quote($oldString->value, '#') . '#');
}

$this->newExpressions[] = $expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ private function collectTypesFromCatchedByIds(TryCatch $tryCatch, array $keys):
$collectedTypes = [];

foreach ($keys as $key) {
$collectedTypes = array_merge($collectedTypes, $tryCatch->catches[$key]->types);
$collectedTypes[] = $tryCatch->catches[$key]->types;
}

if ($collectedTypes !== []) {
$collectedTypes = array_merge([], ...$collectedTypes);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


return $collectedTypes;
Expand Down
9 changes: 6 additions & 3 deletions packages/Symfony/src/Rector/Form/FormIsValidRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ private function findMethodCallNamesOnVariable(Variable $variable): array
$previousMethodCallNames = [];

do {
$methodCallNames = $this->collectMethodCallsOnVariableName($parentNode, $variableName);
$previousMethodCallNames = array_merge($previousMethodCallNames, $methodCallNames);
$previousMethodCallNames[] = $this->collectMethodCallsOnVariableName($parentNode, $variableName);

$parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
} while ($parentNode instanceof Node && ! $parentNode instanceof FunctionLike);

return array_unique($previousMethodCallNames);
if ($previousMethodCallNames !== []) {
$previousMethodCallNames = array_unique(array_merge([], ...$previousMethodCallNames));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


return $previousMethodCallNames;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function unionWithDefaultValueType(Type $type, Type $defaultValueType):
return $defaultValueType;
}

$types = array_merge([$type], [$defaultValueType]);
$types = [$type, $defaultValueType];
Comment thread
voku marked this conversation as resolved.
return $this->typeFactory->createMixedPassedOrUnionType($types);
}
}
11 changes: 9 additions & 2 deletions src/FileSystem/FilesystemTweaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ public function resolveDirectoriesWithFnmatch(array $directories): array
$absoluteDirectories = [];
foreach ($directories as $directory) {
if (Strings::contains($directory, '*')) { // is fnmatch for directories
$absoluteDirectories = array_merge($absoluteDirectories, glob($directory, GLOB_ONLYDIR));
$globDirectory = glob($directory, GLOB_ONLYDIR);
if ($globDirectory !== false) {
$absoluteDirectories[] = $globDirectory;
}
} else { // is classic directory
$this->ensureDirectoryExists($directory);
$absoluteDirectories[] = $directory;
$absoluteDirectories[] = [$directory];
}
}

if ($absoluteDirectories !== []) {
$absoluteDirectories = array_merge([], ...$absoluteDirectories);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


return $absoluteDirectories;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/Psr4/MultipleClassFileToPsr4ClassesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private function processNodesWithoutNamespace(array $nodes, SmartFileInfo $smart
$fileDestination = $this->createClassLikeFileDestination($node, $smartFileInfo);

if ($declareNode) {
$nodes = array_merge([$declareNode], [$node]);
$nodes = [$declareNode, $node];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, let's make a Rector from this:
#2170

} else {
$nodes = [$node];
}
Expand Down