Browse Source

add findByXxx method recognition

Tomas Saghy 7 years ago
parent
commit
e96e50fded
1 changed files with 10 additions and 0 deletions
  1. 10 0
      tests/PHPStan/AssociationTableMixinClassReflectionExtension.php

+ 10 - 0
tests/PHPStan/AssociationTableMixinClassReflectionExtension.php

@@ -43,6 +43,11 @@ class AssociationTableMixinClassReflectionExtension implements PropertiesClassRe
      */
     public function hasMethod(ClassReflection $classReflection, string $methodName): bool
     {
+        // magic findBy* method
+        if ($classReflection->isSubclassOf(Table::class) && preg_match('/^find(?:\w+)?By/', $methodName) > 0) {
+            return true;
+        }
+
         if (!$classReflection->isSubclassOf(Association::class)) {
             return false;
         }
@@ -57,6 +62,11 @@ class AssociationTableMixinClassReflectionExtension implements PropertiesClassRe
      */
     public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
     {
+        // magic findBy* method
+        if ($classReflection->isSubclassOf(Table::class) && preg_match('/^find(?:\w+)?By/', $methodName) > 0) {
+            return new TableFindByPropertyMethodReflection($methodName, $classReflection);
+        }
+
         return $this->getTableReflection()->getNativeMethod($methodName);
     }