1 | <?php |
||
8 | class FixedTextRenderer extends AbstractRenderer |
||
9 | { |
||
10 | /** |
||
11 | * Increase Ciff's 'pitch' value to approximate size in pixels. |
||
12 | * |
||
13 | * @var float |
||
14 | */ |
||
15 | const FONT_SIZE_MULTIPLIER = 4.2; |
||
16 | |||
17 | /** |
||
18 | * @var float |
||
19 | */ |
||
20 | const LETTER_SPACING_ADJUSTMENT = 0.97; |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | const DEFAULT_FONT_SIZE = 13; |
||
26 | |||
27 | /** |
||
28 | * @var callable |
||
29 | */ |
||
30 | protected $fontResolver; |
||
31 | |||
32 | /** |
||
33 | * @param callable $fontResolver |
||
34 | */ |
||
35 | public function setFontResolver(callable $fontResolver) |
||
39 | |||
40 | /** |
||
41 | * @return callable |
||
42 | */ |
||
43 | protected function getFontResolver() |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | protected function getFontFace() |
||
55 | |||
56 | /** |
||
57 | * @return int |
||
58 | */ |
||
59 | protected function getFontSize() |
||
60 | { |
||
61 | $size = $this->parser->getFontSize(); |
||
62 | if (!$size) { |
||
63 | $size = self::DEFAULT_FONT_SIZE; |
||
64 | } |
||
65 | |||
66 | return $size * self::FONT_SIZE_MULTIPLIER; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | protected function getText() |
||
76 | |||
77 | /** |
||
78 | * @return int |
||
79 | */ |
||
80 | protected function getOrientation() |
||
84 | |||
85 | /** |
||
86 | * @return Intervention/Image/Image |
||
87 | */ |
||
88 | 1 | public function render() |
|
126 | } |
||
127 |
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: