| Conditions | 2 |
| Paths | 2 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | public static function handle(ManipulatorInterface $image, array $params = []): ManipulatorInterface |
||
| 34 | { |
||
| 35 | if (false === isset($params['color'])) { |
||
| 36 | throw new Exception('Param "color" is required for action "Background"'); |
||
| 37 | } |
||
| 38 | |||
| 39 | $size = $image->getSize(); |
||
|
|
|||
| 40 | |||
| 41 | $box = new Box($size->getWidth(), $size->getHeight()); |
||
| 42 | $thumb = EasyImage::getImagine()->create($box, new Color( |
||
| 43 | $params['color'], |
||
| 44 | $params['alpha'] ?? 0 |
||
| 45 | )); |
||
| 46 | |||
| 47 | $thumb->paste($image, new Point(0, 0)); |
||
| 48 | |||
| 49 | return $thumb; |
||
| 50 | } |
||
| 51 | } |
||
| 52 |
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: