Conditions | 4 |
Paths | 3 |
Total Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
22 | public static function validate(array $resource): array |
||
23 | { |
||
24 | $resource = parent::validate($resource); |
||
25 | |||
26 | $defaults = [ |
||
27 | 'data' => [ |
||
28 | 'relation' => [], |
||
29 | 'context' => [], |
||
30 | ], |
||
31 | ]; |
||
32 | |||
33 | $resource = array_replace_recursive($defaults, $resource); |
||
34 | |||
35 | if (!is_array($resource['data']['relation']) || count($resource['data']['relation']) !== 2) { |
||
36 | throw new InvalidArgumentException('relation requires data.relation with exactly two objects'); |
||
37 | } |
||
38 | |||
39 | self::validateRelation($resource['data']['relation']); |
||
40 | |||
41 | if (!is_array($resource['data']['context'])) { |
||
42 | throw new InvalidArgumentException('relation requires data.context to be an array'); |
||
43 | } |
||
44 | |||
45 | return $resource; |
||
46 | } |
||
47 | |||
64 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.