Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3.054 |
Changes | 0 |
1 | <?php |
||
34 | 2 | public function stub($class, array $methods = []) |
|
35 | { |
||
36 | 2 | $stub = $this->getMockBuilder($class) |
|
|
|||
37 | 2 | ->disableOriginalConstructor() |
|
38 | 2 | ->getMock(); |
|
39 | |||
40 | 2 | foreach ($methods as $method => $value) { |
|
41 | 1 | if (is_callable($value)) { |
|
42 | $stub->expects($this->any())->method($method)->willReturnCallback($value); |
||
43 | } else { |
||
44 | 1 | $stub->expects($this->any())->method($method)->willReturn($value); |
|
45 | } |
||
46 | 2 | } |
|
47 | |||
48 | 2 | return $stub; |
|
49 | } |
||
50 | } |
||
51 |
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.