Psalm: Detect which method is available in php version?

Created on 13 Feb 2020  Â·  3Comments  Â·  Source: vimeo/psalm

With this example:

class Datetime extends \DateTime
{
    public static function createFromInterface(\DatetimeInterface $datetime): \Datetime
    {
        if (\PHP_VERSION_ID >= 80000) {
            return parent::createFromInterface($datetime);
        }
        //…
    }
}

psalm returns to me:

ERROR: UndefinedMethod - src/Datetime.php - Method DateTime::createfrominterface does not exist
            return parent::createFromInterface($datetime);

Is it a bug? Or I must ignore it because psalm can't detect this kind ot things.

Most helpful comment

somebody (maybe you?) will have to add declarations for methods added to php 8 in a file similar to CallMap_74_delta.php, but named CallMap_80_delta.php

All 3 comments

Here it is a link: https://psalm.dev/r/c6f2bbb578

I found these snippets:


https://psalm.dev/r/c6f2bbb578

<?php

declare(strict_types=1);

namespace FooBar;

class Datetime extends \DateTime
{
    public static function createFromInterface(\DatetimeInterface $datetime)
    {
        if (\PHP_VERSION_ID >= 80000) {
            return parent::createFromInterface($datetime);
        }
    }
}
Psalm output (using commit ae0b1a6):

ERROR: UndefinedMethod - 12:20 - Method DateTime::createfrominterface does not exist

INFO: MissingReturnType - 9:28 - Method FooBar\Datetime::createFromInterface does not have a return type

somebody (maybe you?) will have to add declarations for methods added to php 8 in a file similar to CallMap_74_delta.php, but named CallMap_80_delta.php

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orklah picture orklah  Â·  3Comments

ADmad picture ADmad  Â·  3Comments

muglug picture muglug  Â·  3Comments

sanmai picture sanmai  Â·  4Comments

LeSuisse picture LeSuisse  Â·  3Comments