Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ parameters:
# This should not happen because null is returned on error
- '#Method Apitte\\Core\\Utils\\Helpers::slashless\(\) should return string but returns string\|null\.#'

# Nette changed return typehint
- message: "#^Method Apitte\\\\OpenApi\\\\SchemaDefinition\\\\Entity\\\\EntityAdapter\\:\\:getNativePropertyType\\(\\) should return string but returns array\\<string\\>\\|string\\.$#"
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php

# Nette changed return typehint
- message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, array\\<int, array\\<string\\>\\|string\\> given\\.$#"
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php

- message: "#^Dead catch - TypeError is never thrown in the try block.$#"
path: src/Core/Mapping/Parameter/DateTimeTypeMapper.php
count: 1
10 changes: 8 additions & 2 deletions src/Debug/Tracy/BlueScreen/ValidationBlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Apitte\Core\Exception\Logical\InvalidSchemaException;
use ReflectionClass;
use Throwable;
use Tracy\BlueScreen;
use Tracy\Helpers;

Expand All @@ -12,14 +13,19 @@ class ValidationBlueScreen

public static function register(BlueScreen $blueScreen): void
{
$blueScreen->addPanel(static function ($e): ?array {
$blueScreen->addPanel(static function (?Throwable $e): ?array {
if (!($e instanceof InvalidSchemaException)) {
return null;
}

$panel = self::renderPanel($e);
if ($panel === null) {
return null;
}

return [
'tab' => self::renderTab($e),
'panel' => self::renderPanel($e),
'panel' => $panel,
];
});
}
Expand Down
12 changes: 7 additions & 5 deletions src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,19 @@ private function parseAnnotation(Reflector $ref, string $name): ?string

private function getNativePropertyType(Type $type, ReflectionProperty $property): string
{
if ($type->isSimple() && count($type->getNames()) === 1) {
return $type->getNames()[0];
$names = array_map(strval(...), $type->getTypes());

if ($type->isSimple() && count($names) === 1) {
return $names[0];
}

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

if ($type->isIntersection()) {
return implode('&', $type->getNames());
return implode('&', $names);
}

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