Skip to content

Commit 96e16ea

Browse files
authored
Fix type handling and improve validation error panel rendering (#230)
1 parent eb43d19 commit 96e16ea

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

phpstan.neon

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ parameters:
3939
# This should not happen because null is returned on error
4040
- '#Method Apitte\\Core\\Utils\\Helpers::slashless\(\) should return string but returns string\|null\.#'
4141

42-
# Nette changed return typehint
43-
- message: "#^Method Apitte\\\\OpenApi\\\\SchemaDefinition\\\\Entity\\\\EntityAdapter\\:\\:getNativePropertyType\\(\\) should return string but returns array\\<string\\>\\|string\\.$#"
44-
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
45-
46-
# Nette changed return typehint
47-
- message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, array\\<int, array\\<string\\>\\|string\\> given\\.$#"
48-
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
49-
5042
- message: "#^Dead catch - TypeError is never thrown in the try block.$#"
5143
path: src/Core/Mapping/Parameter/DateTimeTypeMapper.php
5244
count: 1

src/Debug/Tracy/BlueScreen/ValidationBlueScreen.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Apitte\Core\Exception\Logical\InvalidSchemaException;
66
use ReflectionClass;
7+
use Throwable;
78
use Tracy\BlueScreen;
89
use Tracy\Helpers;
910

@@ -12,14 +13,19 @@ class ValidationBlueScreen
1213

1314
public static function register(BlueScreen $blueScreen): void
1415
{
15-
$blueScreen->addPanel(static function ($e): ?array {
16+
$blueScreen->addPanel(static function (?Throwable $e): ?array {
1617
if (!($e instanceof InvalidSchemaException)) {
1718
return null;
1819
}
1920

21+
$panel = self::renderPanel($e);
22+
if ($panel === null) {
23+
return null;
24+
}
25+
2026
return [
2127
'tab' => self::renderTab($e),
22-
'panel' => self::renderPanel($e),
28+
'panel' => $panel,
2329
];
2430
});
2531
}

src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,19 @@ private function parseAnnotation(Reflector $ref, string $name): ?string
275275

276276
private function getNativePropertyType(Type $type, ReflectionProperty $property): string
277277
{
278-
if ($type->isSimple() && count($type->getNames()) === 1) {
279-
return $type->getNames()[0];
278+
$names = array_map(strval(...), $type->getTypes());
279+
280+
if ($type->isSimple() && count($names) === 1) {
281+
return $names[0];
280282
}
281283

282-
if ($type->isUnion() || ($type->isSimple() && count($type->getNames()) === 2) // nullable type is single but returns name of type and null in names
284+
if ($type->isUnion() || ($type->isSimple() && count($names) === 2) // nullable type is single but returns name of type and null in names
283285
) {
284-
return implode('|', $type->getNames());
286+
return implode('|', $names);
285287
}
286288

287289
if ($type->isIntersection()) {
288-
return implode('&', $type->getNames());
290+
return implode('&', $names);
289291
}
290292

291293
throw new RuntimeException(sprintf('Could not parse type "%s"', $property));

0 commit comments

Comments
 (0)