Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 6 |
Ratio | 28.57 % |
Changes | 0 |
1 | <?php |
||
28 | private function resolveGridMetadata(array $grids, string $variant = null) |
||
29 | { |
||
30 | if (empty($grids)) { |
||
31 | throw new \InvalidArgumentException('No grid variants are available'); |
||
32 | } |
||
33 | |||
34 | // if no explicit grid variant is requested, return the first one that |
||
35 | // was defined. |
||
36 | if (null === $variant) { |
||
37 | return reset($grids); |
||
38 | } |
||
39 | |||
40 | View Code Duplication | if (!isset($grids[$variant])) { |
|
|
|||
41 | throw new \InvalidArgumentException(sprintf( |
||
42 | 'Unknown grid variant "%s", available variants: "%s"', |
||
43 | $variant, implode('", "', array_keys($grids)) |
||
44 | )); |
||
45 | } |
||
46 | |||
47 | return $grids[$variant]; |
||
48 | } |
||
49 | } |
||
50 |
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.