Skip to content

Commit

Permalink
Fixed type conversion from bool to string (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
sspat authored Jul 3, 2020
1 parent 5b89f8a commit 532c6ae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Types/ScalarTypesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use cebe\openapi\spec\Type;

use function is_string;
use function Safe\settype;

class ScalarTypesResolver
Expand Down Expand Up @@ -87,8 +88,12 @@ public function convert(bool $deserialize, int $id, $value)
}

if ($deserialize) {
/** phpcs:disable Generic.PHP.ForbiddenFunctions.Found */
settype($value, $format['phpType']);
if (is_string($value) && $format['phpType'] === 'bool') {
$value = $value === 'true';
} else {
/** phpcs:disable Generic.PHP.ForbiddenFunctions.Found */
settype($value, $format['phpType']);
}
}

return $value;
Expand Down

0 comments on commit 532c6ae

Please sign in to comment.