Skip to content

bug: Model::find() returns incorrect type #25

@kenjis

Description

@kenjis

PHP Version

8.2

PHPStan CodeIgniter Version

v1.4.3.70400

PHPStan Version

1.10.58

What happened?

Model::find() returns incorrect type.
See codeigniter4projects/playground#218 (comment)

Minimum Reproduction Script

    public function testMakesMonsterWithDungeon()
    {
        $monster = $this->fabricator->make();
        $dungeon = model(DungeonModel::class)->find($monster->dungeon_id);

        $this->assertInstanceOf(Dungeon::class, $dungeon); // Line 49
    }
 ------ ---------------------------------------------------------------------------------------------------------- 
  Line   tests/database/FakerTest.php                                                                              
 ------ ---------------------------------------------------------------------------------------------------------- 
  49     Call to method PHPUnit\Framework\Assert::assertInstanceOf() with 'App\\Entities\\Dungeon' and array<int,  
         App\Entities\Dungeon> will always evaluate to false.                                                      
         💡 Because the type is coming from a PHPDoc, you can turn off this check by setting                       
            treatPhpDocTypesAsCertain: false in your phpstan.neon.dist.                                            
 ------ ---------------------------------------------------------------------------------------------------------- 

Expected Output

The $dungeon type is App\\Entities\\Dungeon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions