Issues (2)

src/ResponseFormatValidator.php (1 issue)

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
Bug Best Practice introduced by
The expression $responseFormats of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
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