diff --git a/lib/Model.php b/lib/Model.php index cd5ea2a8..044adcd4 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -1481,7 +1481,7 @@ public function reset_dirty(): void /** * Enables the use of dynamic finders. * - * @see Relation->__call() + * @see Relation::__call() */ public static function __callStatic(string $method, mixed $args): static|null { diff --git a/lib/PhpStan/Model/ModelDynamicStaticMethodReturnTypeReflection.php b/lib/PhpStan/Model/ModelDynamicStaticMethodReturnTypeReflection.php index c351a14c..93de04b0 100644 --- a/lib/PhpStan/Model/ModelDynamicStaticMethodReturnTypeReflection.php +++ b/lib/PhpStan/Model/ModelDynamicStaticMethodReturnTypeReflection.php @@ -3,6 +3,7 @@ namespace ActiveRecord\PhpStan\Model; use ActiveRecord\Model; +use ActiveRecord\PhpStan\Relation\RelationReflectionHelper; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; use PhpParser\Node\Name; diff --git a/lib/PhpStan/Model/ModelMethodsClassReflectionExtension.php b/lib/PhpStan/Model/ModelMethodsClassReflectionExtension.php index e5d9b1ee..a5008fd7 100644 --- a/lib/PhpStan/Model/ModelMethodsClassReflectionExtension.php +++ b/lib/PhpStan/Model/ModelMethodsClassReflectionExtension.php @@ -3,6 +3,7 @@ namespace ActiveRecord\PhpStan\Model; use ActiveRecord\Model; +use ActiveRecord\Relation; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\MethodsClassReflectionExtension; @@ -11,7 +12,7 @@ class ModelMethodsClassReflectionExtension implements MethodsClassReflectionExte { public function hasMethod(ClassReflection $classReflection, string $methodName): bool { - if ($classReflection->isSubclassOf(Model::class)) { + if ($classReflection->isSubclassOf(Model::class) || $classReflection->is(Relation::class)) { if (preg_match('/\bfind_by_/', $methodName)) { return true; } diff --git a/lib/PhpStan/Model/ModelStaticMethodReflection.php b/lib/PhpStan/Model/ModelStaticMethodReflection.php index 8b58cc0c..9c39d850 100644 --- a/lib/PhpStan/Model/ModelStaticMethodReflection.php +++ b/lib/PhpStan/Model/ModelStaticMethodReflection.php @@ -10,9 +10,7 @@ use PHPStan\Reflection\FunctionVariant; use PHPStan\Reflection\MethodReflection; use PHPStan\TrinaryLogic; -use PHPStan\Type\ArrayType; use PHPStan\Type\Generic\TemplateTypeMap; -use PHPStan\Type\IntegerType; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\UnionType; @@ -126,21 +124,6 @@ public function getVariants(): array ]) ) ]; - } elseif (str_starts_with($this->name, 'find_all')) { - $parts = SQLBuilder::underscored_string_to_parts(substr($this->name, 9), 0); - - return [ - new FunctionVariant( - TemplateTypeMap::createEmpty(), - TemplateTypeMap::createEmpty(), - array_fill(0, count($parts), new ModelParameterReflection()), - false, - new ArrayType( - new IntegerType(), - new ObjectType($this->classReflection->getDisplayName()), - ) - ) - ]; } elseif (preg_match('/_set$/', $this->name)) { return [ new FunctionVariant( diff --git a/lib/PhpStan/Model/RelationDynamicMethodReturnTypeReflection.php b/lib/PhpStan/Relation/RelationDynamicMethodReturnTypeReflection.php similarity index 97% rename from lib/PhpStan/Model/RelationDynamicMethodReturnTypeReflection.php rename to lib/PhpStan/Relation/RelationDynamicMethodReturnTypeReflection.php index a9883aba..b81d1773 100644 --- a/lib/PhpStan/Model/RelationDynamicMethodReturnTypeReflection.php +++ b/lib/PhpStan/Relation/RelationDynamicMethodReturnTypeReflection.php @@ -1,6 +1,6 @@ find_by_name('Walden'); +assert($book instanceof Book); + +$book = Book::all()->find_by_name_and_publisher('Walden', 'Random House'); +assert(is_null($book));