Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper::toCollection() breaks PHPStan #17

Closed
stpnkcrk opened this issue Aug 31, 2020 · 9 comments
Closed

Mapper::toCollection() breaks PHPStan #17

stpnkcrk opened this issue Aug 31, 2020 · 9 comments

Comments

@stpnkcrk
Copy link

PHPStan 0.12.40
Nextras\Orm 4.0-RC1
Nextras\Orm-PHPStan dev-master

This makes PHPStan with active nextras/orm-phpstan extension to freeze when analysing the file.

<?php declare(strict_types=1);

namespace App\Model\System;

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

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

The issue persists even with just $this->builder() suggesting error isn't in the custom select part.

@hrach
Copy link
Member

hrach commented Aug 31, 2020

Well, the issue here is we try to guess the name of repository. What is FQN name of LogsRepository?

@stpnkcrk
Copy link
Author

App\Model\System\Log (Entity)
App\Model\System\LogMapper
App\Model\System\LogRepository

@stpnkcrk
Copy link
Author

stpnkcrk commented Aug 31, 2020

It seems it's failing on $mapperClass = \get_parent_class($mapperClass); in the MapperMethodReturnTypeExtension.php as that returns false on my machine and therefore it falls into infinite loop.

$mapperClass = $mapper->getClassName();
do {
	/** @phpstan-var class-string<\Nextras\Orm\Repository\Repository> $repositoryClass */
	$repositoryClass = \str_replace('Mapper', 'Repository', $mapperClass);
	$mapperClass = \get_parent_class($mapperClass);
	assert(is_string($mapperClass));
} while (!\class_exists($repositoryClass) && $mapperClass !== DbalMapper::class);

$repositoryClass is recognised correctly as App\Model\System\LogRepository.

@hrach
Copy link
Member

hrach commented Aug 31, 2020

What is your definition of LogRepository? What does it extend?

@stpnkcrk
Copy link
Author

<?php declare(strict_types=1);

namespace App\Model\System;

use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Repository\Repository;

/**
 * @method ICollection|Log[] findAllWithTranslatedIps()
 */
final class LogRepository extends Repository
{
    public static function getEntityClassNames(): array
    {
        return [Log::class];
    }
}

@stpnkcrk
Copy link
Author

@hrach
Copy link
Member

hrach commented Aug 31, 2020

I somehow know where the bug is, will try to fix asap. Thanks for reporting.

@hrach
Copy link
Member

hrach commented Aug 31, 2020

Fixed c7a64f8

@hrach hrach closed this as completed Aug 31, 2020
@stpnkcrk
Copy link
Author

stpnkcrk commented Sep 1, 2020

Thank you very much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants