codeat3 /
foaas-client
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Codeat3\FoaasClient; |
||
| 4 | |||
| 5 | use Codeat3\FoaasClient\Exceptions\InvalidResponse; |
||
| 6 | use Codeat3\FoaasClient\Response\FoaasResponse; |
||
| 7 | |||
| 8 | class ResponseFormatValidator |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Validates and returns the arrays. |
||
| 12 | * |
||
| 13 | * @param array $responseFormats |
||
| 14 | * |
||
| 15 | * @return array |
||
| 16 | */ |
||
| 17 | public static function validate(array $responseFormats): array |
||
| 18 | { |
||
| 19 | if ( |
||
| 20 | $responseFormats |
||
|
0 ignored issues
–
show
|
|||
| 21 | && is_array($responseFormats) |
||
| 22 | && count($responseFormats) > 0 |
||
| 23 | ) { |
||
| 24 | return array_map(static function (string $class) { |
||
| 25 | if (! is_a($class, FoaasResponse::class, true)) { |
||
| 26 | throw new InvalidResponse('A class needs to implement \'Codeat3\FoaasClient\Response\FoaasResponse\''); |
||
| 27 | } |
||
| 28 | |||
| 29 | return $class; |
||
| 30 | }, $responseFormats); |
||
| 31 | } |
||
| 32 | |||
| 33 | return []; |
||
| 34 | } |
||
| 35 | } |
||
| 36 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.