Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed invalid T template parameter from methods where it is not b…
…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 #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
commit ec76a45b9581089d63d304a248014f67d609c31d
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