Conditions | 5 |
Paths | 5 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 27 |
Ratio | 100 % |
Tests | 13 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
28 | 8 | public function getFormatter(FormatInterface $format) |
|
29 | { |
||
30 | 8 | switch ($format->getType()) { |
|
31 | 8 | case 'csv': |
|
32 | 4 | if ($format instanceof CsvFormatInterface) { |
|
33 | 3 | return new CsvFormatter($format); |
|
34 | } else { |
||
35 | 1 | throw new InvalidArgumentException( |
|
36 | 1 | "Format indicates it is csv but does not implement CsvFormatInterface" |
|
37 | ); |
||
38 | } |
||
39 | |||
40 | // fallthrough |
||
41 | 4 | case 'json': |
|
42 | 3 | if ($format instanceof JsonFormatInterface) { |
|
43 | 2 | return new JsonFormatter($format); |
|
44 | } else { |
||
45 | 1 | throw new InvalidArgumentexception( |
|
46 | 1 | "Format indicates it is json but does not implement JsonFormatInterface" |
|
47 | ); |
||
48 | } |
||
49 | |||
50 | // fallthrough |
||
51 | default: |
||
52 | 1 | throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown"); |
|
53 | } |
||
54 | } |
||
55 | } |
||
56 |
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.