Open bpastukh opened 8 months ago
how the string can be upper if we assert it is lowercase?
Assertion is for !lowercase-string
, exclamation mark !
means negation.
The error is:
How exactly is typed $string
? Show /** @psalm-trace $string */;
It is not typed, it's $data
is a dynamic array
#[OA\Property(property: 'data', description: 'An array of data dependent on event type', type: 'object')]
#[Assert\NotBlank]
#[Assert\Type('array')]
public array $data = [],
I'm able to reproduce it this way:
$array = ['someKey' => random_bytes(10)];
$string = $array['someKey'];
Assert::upper($string);
So $array
is not typed (it is defined on the first line of the example) and i'm still getting
ERROR: TypeDoesNotContainType - src/Event/AbstractEvent.php:25:17 - Type non-empty-string for $string is always !lowercase-string (see https://psalm.dev/056)
Assert::upper($string);
As a workaround for now i've used Assert::true
Assert::true(
ctype_upper($string),
sprintf('Expected a value to contain uppercase characters only. Got: "%s"', $string),
);
Indeed, I could reproduce it on the psalm.dev:
What would the correct type assertion be? Or does it even need one?
Hello I'm trying to use Assert::upper() method, but psalm assert
* @psalm-assert !lowercase-string $value
link confuses me - how the string can be upper if we assert it is lowercase?So following code does not pass psalm check:
The error is:
So what is correct usage of upper assertion?