1 | <?php |
||
41 | class CleanUpLinkObserver extends AbstractProductImportObserver implements ObserverFactoryInterface |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * The product link processor instance. |
||
46 | * |
||
47 | * @var \TechDivision\Import\Product\Link\Services\ProductLinkProcessorInterface |
||
48 | */ |
||
49 | protected $productLinkProcessor; |
||
50 | |||
51 | /** |
||
52 | * The array with the link types. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $linkTypes = array(); |
||
57 | |||
58 | /** |
||
59 | * The flag to query whether or not the link types has to be cleaned-up. |
||
60 | * |
||
61 | * @var boolean |
||
62 | */ |
||
63 | protected $cleanUpLinks = false; |
||
64 | |||
65 | /** |
||
66 | * Initialize the observer with the passed product link processor instance. |
||
67 | * |
||
68 | * @param \TechDivision\Import\Product\Link\Services\ProductLinkProcessorInterface $productLinkProcessor The |
||
69 | * product link processor instance |
||
70 | * @param StateDetectorInterface|null $stateDetector The state detector instance to use |
||
71 | */ |
||
72 | public function __construct( |
||
83 | |||
84 | /** |
||
85 | * Will be invoked by the observer visitor when a factory has been defined to create the observer instance. |
||
86 | * |
||
87 | * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance |
||
88 | * |
||
89 | * @return \TechDivision\Import\Observers\ObserverInterface The observer instance |
||
90 | */ |
||
91 | public function createObserver(SubjectInterface $subject) |
||
104 | |||
105 | /** |
||
106 | * Return's the product variant processor instance. |
||
107 | * |
||
108 | * @return \TechDivision\Import\Product\Link\Services\ProductLinkProcessorInterface The product variant processor |
||
109 | * instance |
||
110 | */ |
||
111 | protected function getProductLinkProcessor() |
||
115 | |||
116 | /** |
||
117 | * Process the observer's business logic. |
||
118 | * |
||
119 | * @return void |
||
120 | */ |
||
121 | protected function process() |
||
154 | |||
155 | /** |
||
156 | * This method queries whether or not the column with the passed name is available or |
||
157 | * not. This method uses the `isset()` function to make sure the column is available |
||
158 | * and has not been removed somehow before, because it has an empty value for example. |
||
159 | * |
||
160 | * @param string $name The name of the column to query for |
||
161 | * |
||
162 | * @return boolean TRUE if the columen is available, FALSE otherwise |
||
163 | */ |
||
164 | protected function hasColumn(string $name) : bool |
||
176 | |||
177 | /** |
||
178 | * Delete not exists import links from database. |
||
179 | * |
||
180 | * @param int $parentProductId The ID of the parent product |
||
181 | * @param string $linkTypeCode The link type code to prepare the artefacts for |
||
182 | * @param array $childData The array of variants |
||
183 | * |
||
184 | * @return void |
||
185 | */ |
||
186 | protected function doCleanUp($parentProductId, $linkTypeCode, array $childData) |
||
218 | |||
219 | /** |
||
220 | * Return's the PK to create the product => variant relation. |
||
221 | * |
||
222 | * @return integer The PK to create the relation with |
||
223 | */ |
||
224 | protected function getLastPrimaryKey() |
||
228 | |||
229 | /** |
||
230 | * Return the link type ID for the passed link type code. |
||
231 | * |
||
232 | * @param string $linkTypeCode The link type code to return the link type ID for |
||
233 | * |
||
234 | * @return integer The mapped link type ID |
||
235 | * @throws \TechDivision\Import\Product\Exceptions\MapLinkTypeCodeToIdException Is thrown if the link type code is |
||
236 | * not mapped yet |
||
237 | */ |
||
238 | protected function mapLinkTypeCodeToLinkTypeId($linkTypeCode) |
||
242 | } |
||
243 |
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: