Skip to content

Commit

Permalink
add findByXxx method recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
segy committed Jun 14, 2018
1 parent f130611 commit e96e50f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/PHPStan/AssociationTableMixinClassReflectionExtension.php
Expand Up @@ -43,6 +43,11 @@ protected function getTableReflection(): ClassReflection
*/
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;
}
Expand All @@ -57,6 +62,11 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
*/
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);
}

Expand Down

0 comments on commit e96e50f

Please sign in to comment.