Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
44 | 5 | public function reduce($fn, $initial = null) |
|
45 | { |
||
46 | 5 | $ops = $this->ops; |
|
47 | 5 | $this->vars['_carry'] = $initial; |
|
48 | 5 | if (is_callable($fn)) { |
|
49 | 1 | $fn_name = '_fn' . $this->fn_cnt++; |
|
50 | 1 | $this->vars[$fn_name] = $fn; |
|
51 | 1 | $ops[] = ' $_carry = $' . $fn_name . '($_, $_carry);'; |
|
52 | 1 | } else { |
|
53 | 5 | $ops[] = ' $_carry = ' . $fn . ';'; |
|
54 | } |
||
55 | 5 | $after = '$_result = $_carry;'; |
|
56 | 5 | return self::evaluate($this->seed, $this->vars, $this->compile($ops), '', $after); |
|
57 | } |
||
58 | |||
60 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.