and($node->different(Node::value(''))); } public function matches(Type $other): bool { if ($other instanceof UnionType) { return $other->isMatchedBy($this); } if ($other instanceof ArrayKeyType) { return $other->isMatchedBy($this); } return $other instanceof self || $other instanceof NativeStringType || $other instanceof ScalarConcreteType || $other instanceof MixedType; } public function inferGenericsFrom(Type $other, Generics $generics): Generics { return $generics; } public function canCast(mixed $value): bool { return (is_string($value) || is_numeric($value) || $value instanceof Stringable) && (string)$value !== ''; } public function cast(mixed $value): string { assert($this->canCast($value)); return (string)$value; // @phpstan-ignore-line } public function errorMessage(): ErrorMessage { return MessageBuilder::newError('Value {source_value} is not a valid non-empty string.') ->withCode('invalid_non_empty_string') ->build(); } public function nativeType(): NativeStringType { return NativeStringType::get(); } public function toString(): string { return 'non-empty-string'; } }