Skip to content

Commit

Permalink
Removed invalid T template parameter from methods where it is not b…
Browse files Browse the repository at this point in the history
…ound to any template

These functions had a `T` template parameter in them, but this `T` is completely decoupled
from the one defined at class-level (and therefore at `Enum` instance level, rather than
statically):

 * `Enum::from()`
 * `Enum::isValid()`
 * `Enum::assertValidValue()`
 * `Enum::assertValidValueReturningKey()` (internal detail)

In practice, this means that myclabs#135 (Added new named constructor to create enum from mixed)
was not a valid approach to infer types for enumerable values, when performed statically.

A new approach will be attempted, but the current one will likely need to be scrapped for
now.

In practice, `@psalm-assert`, `@psalm-assert-if-true` and `@psalm-return static<T>` had no
effect on these methods, due to a design-level issue that wasn't spotted (by myself either)
at review.
  • Loading branch information
Ocramius committed Mar 11, 2021
1 parent 96598da commit ec76a45
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __wakeup()
/**
* @param mixed $value
* @return static
* @psalm-return static<T>
* @psalm-return static
*/
public static function from($value): self
{
Expand Down Expand Up @@ -212,7 +212,6 @@ public static function toArray()
* @param $value
* @psalm-param mixed $value
* @psalm-pure
* @psalm-assert-if-true T $value
* @return bool
*/
public static function isValid($value)
Expand All @@ -224,7 +223,6 @@ public static function isValid($value)
* Asserts valid enum value
*
* @psalm-pure
* @psalm-assert T $value
* @param mixed $value
*/
public static function assertValidValue($value): void
Expand All @@ -236,7 +234,6 @@ public static function assertValidValue($value): void
* Asserts valid enum value
*
* @psalm-pure
* @psalm-assert T $value
* @param mixed $value
* @return string
*/
Expand Down

0 comments on commit ec76a45

Please sign in to comment.