Skip to content

Commit

Permalink
fix: Amends psalm assertion syntax on Uuid::isValid() to prevent in…
Browse files Browse the repository at this point in the history
…correct type inference (#486)

* fix: Amends psalm assertion syntax on `Uuid::isValid()` to prevent incorrect type inference
* Add static analysis test case for invalid input
  • Loading branch information
gsteel authored Jan 10, 2023
1 parent 9077ba9 commit 4a14ce0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public static function fromInteger(string $integer): UuidInterface
* @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants,
* but under constant factory setups, this method operates in functionally pure manners
*
* @psalm-assert-if-true non-empty-string $uuid
* @psalm-assert-if-true =non-empty-string $uuid
*/
public static function isValid(string $uuid): bool
{
Expand Down
9 changes: 9 additions & 0 deletions tests/static-analysis/ValidUuidIsNonEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public function givenNonEmptyInputAssertionRemainsValid(string $input): string

throw new InvalidArgumentException('Not a UUID');
}

public function givenInvalidInputValueRemainsAString(string $input): string
{
if (Uuid::isValid($input)) {
return 'It Worked!';
}

return $input;
}
}

0 comments on commit 4a14ce0

Please sign in to comment.