| Conditions | 6 |
| Paths | 6 |
| Total Lines | 30 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function assertArrayStructureEquals(array $structure, array $array) |
||
| 16 | { |
||
| 17 | $structureFirstLevel = array_map(function ($value, $key) { |
||
| 18 | return is_array($value) ? $key : $value; |
||
| 19 | }, $structure, array_keys($structure)); |
||
| 20 | |||
| 21 | $responseFirstLevel = array_keys($array); |
||
| 22 | |||
| 23 | if ($structureFirstLevel !== ['*']) { |
||
| 24 | $this->assertEquals($structureFirstLevel, $responseFirstLevel, '', 0.0, 10, true); |
||
|
|
|||
| 25 | } |
||
| 26 | |||
| 27 | $structureOtherLevels = array_filter($structure, function ($value) { |
||
| 28 | return is_array($value); |
||
| 29 | }); |
||
| 30 | |||
| 31 | foreach ($structureOtherLevels as $key => $childStructure) { |
||
| 32 | if ($key === '*') { |
||
| 33 | $this->assertInternalType('array', $array); |
||
| 34 | |||
| 35 | foreach ($array as $responseDataItem) { |
||
| 36 | $this->assertArrayStructureEquals($childStructure, $responseDataItem); |
||
| 37 | } |
||
| 38 | } else { |
||
| 39 | $this->assertArrayStructureEquals($childStructure, $array[$key]); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | } |
||
| 46 |
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.