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
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public function refactor(Node $node): ?Node
$scope = ScopeFetcher::fetch($node);
$currentClassReflection = $scope->getClassReflection();

$isPDO = $currentClassReflection instanceof ClassReflection && $currentClassReflection->is('PDO');

// It relies on phpstorm stubs that define 2 kind of query method for both php 7.4 and php 8.0
// @see https://github.com/JetBrains/phpstorm-stubs/blob/e2e898a29929d2f520fe95bdb2109d8fa895ba4a/PDO/PDO.php#L1096-L1126
if ($isPDO && $parentMethodReflection->getName() === 'query') {
if ($parentMethodReflection->getName() === 'query'
&& $currentClassReflection instanceof ClassReflection
&& $currentClassReflection->is('PDO')) {
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions rules/Php80/Rector/Identical/StrEndsWithRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,18 @@ private function refactorSubstrCompare(BinaryOp $binaryOp): FuncCall|BooleanNot|
return null;
}

$expr = $funcCallAndExpr->getExpr();
if (! $this->valueResolver->isValue($expr, 0)) {
return null;
}

$substrCompareFuncCall = $funcCallAndExpr->getFuncCall();

$args = $substrCompareFuncCall->getArgs();
if (count($args) < 2) {
return null;
}

$expr = $funcCallAndExpr->getExpr();
if (! $this->valueResolver->isValue($expr, 0)) {
return null;
}

$haystack = $args[0]->value;
$needle = $args[1]->value;
$thirdArgValue = $args[2]->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ private function getEnumConstFetch(StaticCall $staticCall): null|ClassConstFetch

private function refactorMethodCall(MethodCall $methodCall, string $methodName): null|PropertyFetch|Identical
{
if (! in_array($methodName, ['getKey', 'getValue', 'equals'], true)) {
return null;
}

if (! $this->isObjectType($methodCall->var, new ObjectType('MyCLabs\Enum\Enum'))) {
return null;
}
Expand All @@ -291,11 +295,7 @@ private function refactorMethodCall(MethodCall $methodCall, string $methodName):
return $this->refactorGetValueMethodCall($methodCall);
}

if ($methodName === 'equals') {
return $this->refactorEqualsMethodCall($methodCall);
}

return null;
return $this->refactorEqualsMethodCall($methodCall);
}

private function shouldOmitEnumCase(string $enumCaseName): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,19 @@ private function refactorGetterToMethodCall(MethodCall $methodCall, string $prop

private function refactorMethodCall(MethodCall $methodCall, string $methodName): null|PropertyFetch
{
if (! $this->isObjectType($methodCall->var, new ObjectType(self::SPATIE_FQN))) {
if (! in_array($methodName, ['getName', 'label', 'getValue', 'value'], true)) {
return null;
}

if ($methodName === 'getName') {
return $this->refactorGetterToMethodCall($methodCall, 'name');
if (! $this->isObjectType($methodCall->var, new ObjectType(self::SPATIE_FQN))) {
return null;
}

if ($methodName === 'label') {
if (in_array($methodName, ['getName', 'label'], true)) {
return $this->refactorGetterToMethodCall($methodCall, 'name');
}

if ($methodName === 'getValue') {
return $this->refactorGetterToMethodCall($methodCall, 'value');
}

if ($methodName === 'value') {
return $this->refactorGetterToMethodCall($methodCall, 'value');
}

return null;
return $this->refactorGetterToMethodCall($methodCall, 'value');
}

private function shouldOmitEnumCase(string $enumCaseName): bool
Expand Down
7 changes: 4 additions & 3 deletions rules/Php83/Rector/ClassConst/AddTypeToConstRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function refactor(Node $node): ?Class_
return null;
}

$parentClassReflections = $this->getParentReflections($className);
$parentClassReflections = null;

$hasChanged = false;

Expand All @@ -104,11 +104,12 @@ public function refactor(Node $node): ?Class_
continue;
}

if ($this->isConstGuardedByParents($constNode, $parentClassReflections)) {
if ($this->canBeInherited($classConst, $node)) {
continue;
}

if ($this->canBeInherited($classConst, $node)) {
$parentClassReflections ??= $this->getParentReflections($className);
if ($this->isConstGuardedByParents($constNode, $parentClassReflections)) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions rules/Php84/Rector/FuncCall/AddEscapeArgumentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public function refactor(Node $node): null|FuncCall|MethodCall
return null;
}

if (! $this->isObjectType($node->var, new ObjectType('SplFileObject'))) {
return null;
}

if ($this->shouldSkipNamedArg($node)) {
return null;
}
Expand All @@ -97,6 +93,10 @@ public function refactor(Node $node): null|FuncCall|MethodCall
return null;
}

if (! $this->isObjectType($node->var, new ObjectType('SplFileObject'))) {
return null;
}

$node->args[count($node->getArgs())] = new Arg(new String_('\\'), name: new Identifier('escape'));
return $node;
}
Expand Down
Loading