| Conditions | 3 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function compile(\Twig_Compiler $compiler) |
||
| 22 | { |
||
| 23 | $compiler->raw( |
||
| 24 | sprintf( |
||
| 25 | '$this->env->getExtension(\'%s\')->%s(', |
||
| 26 | 'Translation\Bundle\Twig\TranslationExtension', |
||
| 27 | 'transchoiceWithDefault' |
||
| 28 | ) |
||
| 29 | ); |
||
| 30 | |||
| 31 | $first = true; |
||
| 32 | foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { |
||
|
|
|||
| 33 | if (!$first) { |
||
| 34 | $compiler->raw(', '); |
||
| 35 | } |
||
| 36 | $first = false; |
||
| 37 | |||
| 38 | $compiler->subcompile($pair['value']); |
||
| 39 | } |
||
| 40 | |||
| 41 | $compiler->raw(')'); |
||
| 42 | } |
||
| 43 | } |
||
| 44 |
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 sub-classes 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 parent class: