Skip to content

Upgrade to Psalm 5 #168

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

Merged
merged 2 commits into from
Dec 13, 2022
Merged

Upgrade to Psalm 5 #168

merged 2 commits into from
Dec 13, 2022

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.

@@ -308,7 +310,6 @@ public static function __callStatic($name, $arguments)
*
* @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