Conditions | 5 |
Paths | 10 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
24 | protected function doCrop($width, $height, $x, $y) |
||
25 | { |
||
26 | $option = '-crop'; |
||
27 | |||
28 | $geometry = $this->geometry(); |
||
29 | if ($geometry) { |
||
30 | $params = [ $option.' '.$geometry ]; |
||
31 | } else { |
||
32 | $params = [ '-gravity "'.$this->gravity().'"' ]; |
||
33 | |||
34 | $size = $width.'x'.$height.($x >= 0 ? '+' : '').$x.($y >= 0 ? '+' : '').$y; |
||
35 | $params[] = $option.' '.$size; |
||
36 | } |
||
37 | |||
38 | if ($this->repage()) { |
||
39 | $params[] = '+repage'; |
||
40 | } |
||
41 | |||
42 | $this->image()->applyCmd(implode(' ', $params)); |
||
|
|||
43 | } |
||
44 | } |
||
45 |
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: