Skip to content

Commit

Permalink
Merge pull request #9 from sidz/use-phpstan-2
Browse files Browse the repository at this point in the history
Support PHPStan 2
  • Loading branch information
sidz authored Jan 15, 2025
2 parents 2d96028 + 3cb307e commit 21673aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
],
"require": {
"php": "^7.4",
"phpstan/phpstan": "^1.9"
"phpstan/phpstan": "^2.0"
},
"require-dev": {
"cakephp/cakephp": "^2.10.24",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.6",
"nunomaduro/phpinsights": "^2.7"
"nunomaduro/phpinsights": "^2.7",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^9.6"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -62,6 +62,7 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"sort-packages": true
}
}
20 changes: 9 additions & 11 deletions src/ClassRegistryInitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo

public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type
{
$argumentType = $scope->getType($methodCall->getArgs()[0]->value);
$type = $scope->getType($methodCall->getArgs()[0]->value);

if (!$argumentType instanceof ConstantStringType) {
return $this->getDefaultType();
}

$value = $argumentType->getValue();
foreach ($type->getConstantStrings() as $constantString) {
$value = $constantString->getValue();

if ($this->reflectionProvider->hasClass($value)) {
return new ObjectType($value);
}
if ($this->reflectionProvider->hasClass($value)) {
return new ObjectType($value);
}

if ($this->schemaService->hasTable(Inflector::tableize($value))) {
return new ObjectType('Model');
if ($this->schemaService->hasTable(Inflector::tableize($value))) {
return new ObjectType('Model');
}
}

return $this->getDefaultType();
Expand Down

0 comments on commit 21673aa

Please sign in to comment.