Skip to content

Commit 5cd6758

Browse files
committed
Fixed some Psalm issues
1 parent e025127 commit 5cd6758

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/Utils/PhpUnitUtil.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public static function getInvalidValueForType(string $type): DateTime | stdClass
261261
*/
262262
private static function getValidValue(
263263
?array $meta,
264-
string $type
264+
string $type,
265265
): mixed {
266266
$meta ??= [];
267267

@@ -272,6 +272,16 @@ private static function getValidValue(
272272
/** @var class-string $class */
273273
$class = $meta !== [] && array_key_exists('targetEntity', $meta) ? $meta['targetEntity'] : $type;
274274

275+
if (!class_exists($class)) {
276+
throw new LogicException(
277+
sprintf(
278+
"Cannot create valid value for type '%s' because class '%s' does not exist.",
279+
$type,
280+
$class,
281+
),
282+
);
283+
}
284+
275285
$type = self::TYPE_CUSTOM_CLASS;
276286

277287
if ((new ReflectionClass($class))->isEnum()) {
@@ -286,6 +296,7 @@ private static function getValidValue(
286296
}
287297
}
288298

299+
/** @var mixed $output */
289300
$output = match ($type) {
290301
self::TYPE_ENUM => current($class::cases()), // TODO: fix this
291302
self::TYPE_CUSTOM_CLASS => new $class(...$params),
@@ -299,6 +310,7 @@ private static function getValidValue(
299310
};
300311

301312
if (str_contains($type, '|')) {
313+
/** @var mixed $output */
302314
$output = self::getValidValueForType(explode('|', $type)[0], $meta);
303315
} elseif (str_contains($type, '[]')) {
304316
/** @var array<mixed, object> $output */

0 commit comments

Comments
 (0)