| Conditions | 5 |
| Paths | 5 |
| Total Lines | 25 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 25 | public function render(RenderInterface $renderer, QueryInterface $query, $object) |
||
| 26 | { |
||
| 27 | $status = ''; |
||
| 28 | switch ($object->status) { |
||
| 29 | case 0: |
||
| 30 | $status = 'New'; |
||
| 31 | break; |
||
| 32 | case 1: |
||
| 33 | $status = 'Delivered'; |
||
| 34 | break; |
||
| 35 | case 2: |
||
| 36 | $status = 'Declined'; |
||
| 37 | break; |
||
| 38 | case 3: |
||
| 39 | $status = 'Deleted'; |
||
| 40 | break; |
||
| 41 | } |
||
| 42 | // Render input field view |
||
| 43 | return $renderer |
||
|
|
|||
| 44 | ->view($this->innerView) |
||
| 45 | ->set('class', $this->css) |
||
| 46 | ->set($object, 'item') |
||
| 47 | ->set('status', $status) |
||
| 48 | ->output(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
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: