| Conditions | 3 |
| Paths | 3 |
| Total Lines | 11 |
| Code Lines | 7 |
| Lines | 7 |
| Ratio | 63.64 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | public function testToArray() |
||
| 27 | { |
||
| 28 | $array = $this->source->toArray(); |
||
|
|
|||
| 29 | View Code Duplication | foreach ($array as $item) { |
|
| 30 | $this->assertInternalType('array', $item); |
||
| 31 | foreach ($item as $key => $value) { |
||
| 32 | $this->assertInternalType('string', $key); |
||
| 33 | $this->assertInstanceOf(\Magento\Framework\Phrase::class, $value); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: