Skip to content

Conversation

@rogervila
Copy link
Contributor

Hi,

When upgrading to Psalm 5, there are some errors that have appeared:

ERROR: UnsafeGenericInstantiation - src/Enum.php:179:29 - Cannot safely instantiate generic class MyCLabs\Enum\Enum with "new static" as its generic parameters may be constrained in child classes. (see https://psalm.dev/269)
            $values[$key] = new static($value);


ERROR: UnsafeGenericInstantiation - src/Enum.php:300:54 - Cannot safely instantiate generic class MyCLabs\Enum\Enum with "new static" as its generic parameters may be constrained in child classes. (see https://psalm.dev/269)
            return self::$instances[$class][$name] = new static($array[$name]);


ERROR: ImpureMethodCall - src/Enum.php:313:7 - Cannot call an impure constructor from a pure context (see https://psalm.dev/203)
    #[\ReturnTypeWillChange]

I have silenced them as a first approach. We can fix them on this PR or create another one once this is one is merged.

*
* @return mixed
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @psalm-pure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this error:

ERROR: ImpureMethodCall - src/Enum.php:313:7 - Cannot call an impure constructor from a pure context (see https://psalm.dev/203)
    #[\ReturnTypeWillChange]

We should either remove @psalm-pure or #[\ReturnTypeWillChange]

Since Enum's JSON serialization can be anything, We may keep the second one.

@mnapoli
Copy link
Member

mnapoli commented Dec 13, 2022

Thanks! Since this package still supports PHP 7.3 I'm not sure if we shouldn't require Psalm 4|5?

@peter279k
Copy link

peter279k commented Dec 13, 2022

According to the composer.json of latest Psalm version, it should require php-7.4 version at least.

@rogervila
Copy link
Contributor Author

Thank you @peter279k, let me modify to support also v4

@mnapoli
Copy link
Member

mnapoli commented Dec 13, 2022

Thanks!

@mnapoli mnapoli merged commit 6707446 into myclabs:master Dec 13, 2022
@rogervila rogervila deleted the psalm-5 branch December 13, 2022 11:16
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

Successfully merging this pull request may close these issues.

3 participants