Conditions | 4 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | protected function doResize($width, $height, $bestFit = false) |
||
24 | { |
||
25 | $cmd = [ |
||
26 | '-gravity "'.$this->gravity().'"', |
||
27 | '-background "'.$this->backgroundColor().'"' |
||
28 | ]; |
||
29 | |||
30 | if ($this->adaptive()) { |
||
31 | $option = '-adaptive-resize'; |
||
32 | } else { |
||
33 | $option = '-resize'; |
||
34 | } |
||
35 | |||
36 | $size = $this->size(); |
||
37 | if ($size) { |
||
38 | $cmd[] = $option.' '.$size; |
||
39 | } else { |
||
40 | $size = $width.'x'.$height; |
||
41 | if ($bestFit) { |
||
42 | $cmd[] = $option.' '.$size.'^'; |
||
43 | $cmd[] = '-extent '.$size; |
||
44 | } else { |
||
45 | $cmd[] = $option.' '.$size; |
||
46 | } |
||
47 | } |
||
48 | |||
49 | $this->image()->applyCmd(implode(' ', $cmd)); |
||
|
|||
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: