Skip to content

Commit

Permalink
mapper type extension: fix resolving parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Aug 31, 2020
1 parent dc15377 commit c7a64f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Types/MapperMethodReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,20 @@ public function getTypeFromMethodCall(
return $defaultReturn;
}

$mapperClass = $mapper->getClassName();
$currentMapper = $this->reflectionProvider->getClass($mapper->getClassName());
assert($currentMapper !== false);

do {
$mapperClass = $currentMapper->getName();
/** @phpstan-var class-string<\Nextras\Orm\Repository\Repository> $repositoryClass */
$repositoryClass = \str_replace('Mapper', 'Repository', $mapperClass);
$mapperClass = \get_parent_class($mapperClass);

$currentMapper = $this->reflectionProvider->getClass($mapperClass)->getParentClass();
if ($currentMapper === false) {
break;
}
$mapperClass = $currentMapper->getName();

assert(is_string($mapperClass));
} while (!\class_exists($repositoryClass) && $mapperClass !== DbalMapper::class);

Expand Down
7 changes: 7 additions & 0 deletions tests/testbox/Types/fixtures/AuthorsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

namespace NextrasTests\OrmPhpStan\Types;

use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Mapper\Mapper;


class AuthorsMapper extends Mapper
{
public function findAllWithTranslatedIps(): ICollection
{
return $this->toCollection(
$this->builder()->addSelect('inet6_ntoa([ip]) as [ip]')
);
}
}

0 comments on commit c7a64f8

Please sign in to comment.