Files
php-uuid/tests/static-analysis/ValidUuidIsNonEmpty.php
T
George Steel b4dff559ab Assert non-empty-string when UUID is valid (#410)
* Assert, for psalm, the string is non-empty if validation passes
* Adds a test for SA asserting that valid string are also non-empty
* Suppress PHPStan error for unsupported conditional type assertion
* Check SA tools don't complain about non-empty-string as input parameter to `Uuid::isValid()`
2022-08-09 10:04:36 -05:00

36 lines
729 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');
}
}