1 | <?php |
||
8 | class FixedTextRenderer extends AbstractRenderer |
||
9 | { |
||
10 | const FONT_SIZE_MULTIPLIER = 4.2; |
||
11 | |||
12 | const LETTER_SPACING_ADJUSTMENT = 0.97; |
||
13 | |||
14 | /** |
||
15 | * @var callable |
||
16 | */ |
||
17 | protected $fontResolver; |
||
18 | |||
19 | /** |
||
20 | * @param callable $fontResolver |
||
21 | */ |
||
22 | public function setFontResolver(callable $fontResolver) |
||
26 | |||
27 | /** |
||
28 | * @return callable |
||
29 | */ |
||
30 | protected function getFontResolver() |
||
34 | |||
35 | /** |
||
36 | * @return string |
||
37 | */ |
||
38 | protected function getFontFace() |
||
42 | |||
43 | /** |
||
44 | * @return int |
||
45 | */ |
||
46 | protected function getFontSize() |
||
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | protected function getText() |
||
58 | |||
59 | /** |
||
60 | * @return int |
||
61 | */ |
||
62 | protected function getOrientation() |
||
66 | |||
67 | /** |
||
68 | * @return Intervention/Image/Image |
||
69 | */ |
||
70 | 1 | public function render() |
|
103 | } |
||
104 |
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: