-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On the road to phpstan 2.0 compatibility #334
base: master
Are you sure you want to change the base?
Changes from all commits
949f032
8a39cd2
1db3519
f21b5ce
131d11f
6c5ded9
0aca521
eb3e763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,9 @@ protected function getFileContents(string $class): string | |
$defaultValue = ' = false'; | ||
break; | ||
default: | ||
$defaultValue = ' = ' . $parameter->getDefaultValue(); | ||
if (is_string($parameter->getDefaultValue())) { | ||
$defaultValue = ' = ' . $parameter->getDefaultValue(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is a good solution, |
||
break; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
use PhpParser\Node\Expr\MethodCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\ShouldNotHappenException; | ||
use PHPStan\Rules\RuleError; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use PHPStan\Type\Constant\ConstantStringType; | ||
use PHPStan\Type\ErrorType; | ||
use PHPStan\Type\ObjectType; | ||
|
@@ -38,18 +39,8 @@ | |
return MethodCall::class; | ||
} | ||
|
||
/** | ||
* @param Node $node | ||
* @param Scope $scope | ||
* @return (string|\PHPStan\Rules\RuleError)[] errors | ||
* @throws ShouldNotHappenException | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
if (!$node instanceof MethodCall) { | ||
throw new ShouldNotHappenException(); | ||
} | ||
|
||
if (!$node->name instanceof Node\Identifier) { | ||
return []; | ||
} | ||
|
@@ -77,12 +68,17 @@ | |
/** @var \PhpParser\Node\Arg[] $args */ | ||
$args = $node->args; | ||
/** @var ConstantStringType $argType */ | ||
$argType = $scope->getType($args[0]->value); | ||
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (8.1, 2.4.5, ubuntu-latest)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.3, false)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (8.1, 2.4.4, ubuntu-latest)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2-p2, false)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (8.1, 2.4.6, ubuntu-latest, true)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (ubuntu-latest, 7.4, 2.3.7-p2, false)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2, false)
Check failure on line 71 in src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2-p1, false)
|
||
|
||
return [ | ||
sprintf( | ||
'%s does not extend \Magento\Framework\Data\Collection as required!', | ||
$argType->getValue() | ||
RuleErrorBuilder::message( | ||
sprintf( | ||
'%s does not extend \Magento\Framework\Data\Collection as required!', | ||
$argType->getValue() | ||
) | ||
) | ||
->identifier('bitExpertMagento.getCollectionMockMethodNeedsCollectionSubclass') | ||
->build() | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,6 @@ | |
|
||
class TestFrameworkObjectManagerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getClass(): string | ||
{ | ||
return 'Magento\Framework\TestFramework\Unit\Helper\ObjectManager'; | ||
|
@@ -92,10 +89,16 @@ | |
/** @var \PhpParser\Node\Arg[] $args */ | ||
$args = $methodCall->args; | ||
$argType = $scope->getType($args[0]->value); | ||
if (!$argType instanceof ConstantStringType) { | ||
if ($argType->getConstantStrings() === []) { | ||
return $mixedType; | ||
} | ||
return TypeCombinator::addNull(new ObjectType($argType->getValue())); | ||
|
||
$types = []; | ||
foreach ($argType->getConstantStrings() as $constantString) { | ||
$types[] = TypeCombinator::addNull(new ObjectType($constantString->getValue())); | ||
} | ||
|
||
return TypeCombinator::union(...$types); | ||
} | ||
|
||
/** | ||
|
@@ -126,10 +129,10 @@ | |
/** @var \PhpParser\Node\Arg[] $args */ | ||
$args = $methodCall->args; | ||
/** @var ConstantStringType $type */ | ||
$type = $scope->getType($args[0]->value); | ||
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (8.1, 2.4.5, ubuntu-latest)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.3, false)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (8.1, 2.4.4, ubuntu-latest)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2-p2, false)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (8.1, 2.4.6, ubuntu-latest, true)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.3.7-p2, false)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2, false)
Check failure on line 132 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2-p1, false)
|
||
/** @var string $className */ | ||
$className = $type->getValue(); | ||
if (!is_subclass_of($className, 'Magento\Framework\Data\Collection')) { | ||
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (8.1, 2.4.5, ubuntu-latest)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.3, false)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (8.1, 2.4.4, ubuntu-latest)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2-p2, false)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (8.1, 2.4.6, ubuntu-latest, true)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.3.7-p2, false)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2, false)
Check failure on line 135 in src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php GitHub Actions / run (ubuntu-latest, 7.4, 2.4.2-p1, false)
|
||
return new \PHPStan\Type\ErrorType(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this change, it's to keep phpstan stop from complaining about
preg_replace
to returnnull
in case of a failure. Maybe we should mark to ignore this phpstan error?