mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
4a14ce0c62
* fix: Amends psalm assertion syntax on `Uuid::isValid()` to prevent incorrect type inference * Add static analysis test case for invalid input
45 lines
926 B
PHP
45 lines
926 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Ramsey\Uuid\StaticAnalysis;
|
|
|
|
use InvalidArgumentException;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
final class ValidUuidIsNonEmpty
|
|
{
|
|
/** @return non-empty-string */
|
|
public function validUuidsAreNotEmpty(string $input): string
|
|
{
|
|
if (Uuid::isValid($input)) {
|
|
return $input;
|
|
}
|
|
|
|
throw new InvalidArgumentException('Not a UUID');
|
|
}
|
|
|
|
/**
|
|
* @param non-empty-string $input
|
|
*
|
|
* @return non-empty-string
|
|
*/
|
|
public function givenNonEmptyInputAssertionRemainsValid(string $input): string
|
|
{
|
|
if (Uuid::isValid($input)) {
|
|
return $input;
|
|
}
|
|
|
|
throw new InvalidArgumentException('Not a UUID');
|
|
}
|
|
|
|
public function givenInvalidInputValueRemainsAString(string $input): string
|
|
{
|
|
if (Uuid::isValid($input)) {
|
|
return 'It Worked!';
|
|
}
|
|
|
|
return $input;
|
|
}
|
|
}
|