| Conditions | 6 |
| Paths | 12 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 6.288 |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | 2 | protected function stub( |
|
| 37 | 2 | string $class, |
|
| 38 | 2 | array $methods = [], |
|
| 39 | string $className = '', |
||
| 40 | 2 | bool $forceMethods = false |
|
| 41 | 1 | ) : \PHPUnit_Framework_MockObject_MockObject { |
|
| 42 | $builder = $this->getMockBuilder($class) |
||
|
|
|||
| 43 | ->disableOriginalConstructor(); |
||
| 44 | 1 | ||
| 45 | if (!empty($methods) && $forceMethods) { |
||
| 46 | 2 | $builder->setMethods(array_keys($methods)); |
|
| 47 | } |
||
| 48 | 2 | ||
| 49 | if ('' !== $className) { |
||
| 50 | $builder->setMockClassName($className); |
||
| 51 | } |
||
| 52 | |||
| 53 | $stub = $builder->getMock(); |
||
| 54 | foreach ($methods as $method => $value) { |
||
| 55 | if (is_callable($value)) { |
||
| 56 | $stub->expects($this->any())->method($method)->willReturnCallback($value); |
||
| 57 | } else { |
||
| 58 | $stub->expects($this->any())->method($method)->willReturn($value); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | return $stub; |
||
| 63 | } |
||
| 64 | } |
||
| 65 |
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
Idableprovides a methodequalsIdthat 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.