1 | <?php |
||
17 | class PageSeoHelper |
||
18 | { |
||
19 | protected $businessEntityHelper = null; |
||
20 | protected $parameterConverter = null; |
||
21 | |||
22 | protected $pageSeoAttributes = [ |
||
23 | 'metaTitle', |
||
24 | 'metaDescription', |
||
25 | 'relAuthor', |
||
26 | 'relPublisher', |
||
27 | 'ogTitle', |
||
28 | 'ogType', |
||
29 | 'ogImage', |
||
30 | 'ogUrl', |
||
31 | 'ogDescription', |
||
32 | 'fbAdmins', |
||
33 | 'twitterCard', |
||
34 | 'twitterUrl', |
||
35 | 'twitterTitle', |
||
36 | 'twitterDescription', |
||
37 | 'twitterImage', |
||
38 | 'schemaPageType', |
||
39 | 'schemaName', |
||
40 | 'schemaDescription', |
||
41 | 'schemaImage', |
||
42 | 'metaRobotsIndex', |
||
43 | 'metaRobotsFollow', |
||
44 | 'metaRobotsAdvanced', |
||
45 | 'relCanonical', |
||
46 | 'keyword', ]; |
||
47 | |||
48 | /** |
||
49 | * Constructor. |
||
50 | * |
||
51 | * @param BusinessEntityHelper $businessEntityHelper |
||
52 | * @param ParameterConverter $parameterConverter |
||
53 | */ |
||
54 | public function __construct(BusinessEntityHelper $businessEntityHelper, ParameterConverter $parameterConverter) |
||
59 | |||
60 | /** |
||
61 | * Generate a seo for the page using the current entity. |
||
62 | * |
||
63 | * @param Page $page |
||
64 | * @param Entity $entity |
||
65 | */ |
||
66 | public function updateSeoByEntity(BasePage $page, $entity) |
||
109 | |||
110 | /** |
||
111 | * Update the value of the entity. |
||
112 | * |
||
113 | * @param \Victoire\Bundle\SeoBundle\Entity\PageSeo $entity |
||
114 | * @param string $field |
||
115 | * @param string $value |
||
116 | * |
||
117 | * @return mixed |
||
118 | */ |
||
119 | protected function setEntityAttributeValue($entity, $field, $value) |
||
125 | } |
||
126 |
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 sub-classes 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 parent class: