Conditions | 8 |
Paths | 20 |
Total Lines | 40 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | protected function doResize($width, $height, $bestFit = false) |
||
24 | { |
||
25 | if ($this->adaptive()) { |
||
26 | $option = '-adaptive-resize'; |
||
27 | } else { |
||
28 | $option = '-resize'; |
||
29 | } |
||
30 | |||
31 | $size = $this->size(); |
||
32 | if ($size) { |
||
33 | $params = [ $option.' '.$size ]; |
||
34 | } else { |
||
35 | if ($width === 0 && $height === 0) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | $params = [ |
||
40 | '-gravity "'.$this->gravity().'"', |
||
41 | '-background "'.$this->backgroundColor().'"' |
||
42 | ]; |
||
43 | |||
44 | if ($width === 0) { |
||
45 | $width = ''; |
||
46 | } |
||
47 | |||
48 | if ($height === 0) { |
||
49 | $height = ''; |
||
50 | } |
||
51 | |||
52 | $size = $width.'x'.$height; |
||
53 | if ($bestFit) { |
||
54 | $params[] = $option.' '.$size.'^'; |
||
55 | $params[] = '-extent '.$size; |
||
56 | } else { |
||
57 | $params[] = $option.' '.$size; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | $this->image()->applyCmd(implode(' ', $params)); |
||
|
|||
62 | } |
||
63 | } |
||
64 |
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: