Conditions | 4 |
Paths | 4 |
Total Lines | 15 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
24 | 41 | public function __construct($enumClass, $set = []) |
|
25 | { |
||
26 | // if enum class was sent, we must make sure it is valid |
||
27 | 41 | $this->setEnumClass($enumClass); |
|
28 | |||
29 | 39 | if (!is_array($set)) { |
|
30 | 2 | throw new EnumSetMustContainEnumsException(sprintf("Enum set must be initialized with array of enums.")); |
|
31 | } |
||
32 | 37 | foreach ($set as $enum) { |
|
33 | 35 | if (!($enum instanceof $this->enumClass)) { |
|
34 | 6 | throw new EnumSetMustContainEnumsException(sprintf("Expected %s, got %s", $this->enumClass, get_class($enum))); |
|
35 | } |
||
36 | 31 | $this->set[(string) $enum] = $enum; |
|
37 | 33 | } |
|
38 | 31 | } |
|
39 | |||
79 |
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.