| Conditions | 2 |
| Paths | 2 |
| Total Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function render(array $params = []): string |
||
| 25 | { |
||
| 26 | $fullPath = Module::getInstance()->getStorage()->getLocalPath($this->path); |
||
|
|
|||
| 27 | $mimeType = mime_content_type($fullPath); |
||
| 28 | |||
| 29 | if ($mimeType !== 'text/plain') { |
||
| 30 | throw new \Exception('unexpected mime type for behat feature file'); |
||
| 31 | } |
||
| 32 | |||
| 33 | $text = Module::getInstance()->getStorage()->read($this->path); |
||
| 34 | $text = preg_replace('/\b(Feature|Scenario|Background:)\b/', '<b class=behat-command>\1</b>', $text); |
||
| 35 | $text = preg_replace('/(@\S+)\b/', '<b class=behat-tag>\1</b>', $text); |
||
| 36 | $text = preg_replace('/\b(Given|And|When|Then)\b/', '<b class=behat-step>\1</b>', $text); |
||
| 37 | |||
| 38 | return "<pre>$text</pre>"; |
||
| 39 | } |
||
| 40 | |||
| 46 |
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: