Conditions | 3 |
Paths | 3 |
Total Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
39 | public function __construct(int $column, $value, array $groups, float $impurity) |
||
40 | { |
||
41 | if (count($groups) !== 2) { |
||
42 | throw new InvalidArgumentException('The number of groups must be exactly two.'); |
||
43 | } |
||
44 | |||
45 | if ($impurity < 0.) { |
||
46 | throw new InvalidArgumentException('Impurity cannot be less than 0.'); |
||
47 | } |
||
48 | |||
49 | $this->column = $column; |
||
50 | $this->value = $value; |
||
51 | $this->groups = $groups; |
||
52 | $this->impurity = $impurity; |
||
53 | $this->samplesCount = (int) array_sum(array_map(function (array $group) { |
||
54 | return count($group[0]); |
||
55 | }, $groups)); |
||
56 | } |
||
57 | |||
108 |
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.