1 | <?php |
||
39 | class CleanUpLinkObserver extends AbstractProductImportObserver |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * The product link processor instance. |
||
44 | * |
||
45 | * @var \TechDivision\Import\Product\Link\Services\ProductLinkProcessorInterface |
||
46 | */ |
||
47 | protected $productLinkProcessor; |
||
48 | |||
49 | /** |
||
50 | * Initialize the observer with the passed product link processor instance. |
||
51 | * |
||
52 | * @param \TechDivision\Import\Product\Link\Services\ProductLinkProcessorInterface $productLinkProcessor The |
||
53 | * product link processor instance |
||
54 | * @param StateDetectorInterface|null $stateDetector The state detector instance to use |
||
55 | */ |
||
56 | public function __construct( |
||
67 | |||
68 | /** |
||
69 | * Return's the product variant processor instance. |
||
70 | * |
||
71 | * @return \TechDivision\Import\Product\Link\Services\ProductLinkProcessorInterface The product variant processor |
||
72 | * instance |
||
73 | */ |
||
74 | protected function getProductLinkProcessor() |
||
78 | |||
79 | /** |
||
80 | * Process the observer's business logic. |
||
81 | * |
||
82 | * @return void |
||
83 | * @throws \Exception |
||
84 | */ |
||
85 | protected function process() |
||
117 | |||
118 | /** |
||
119 | * This method queries whether or not the column with the passed name is available or |
||
120 | * not. This method uses the `isset()` function to make sure the column is available |
||
121 | * and has not been removed somehow before, because it has an empty value for example. |
||
122 | * |
||
123 | * @param string $name |
||
124 | * |
||
125 | * @return boolean TRUE if the columen is available, FALSE otherwise |
||
126 | */ |
||
127 | protected function hasColumn(string $name) : bool |
||
139 | |||
140 | /** |
||
141 | * Delete not exists import links from database. |
||
142 | * |
||
143 | * @param int $parentProductId The ID of the parent product |
||
144 | * @param string $linkTypeCode The link type code to prepare the artefacts for |
||
145 | * @param array $childData The array of variants |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | protected function cleanUpLinks($parentProductId, $linkTypeCode, array $childData) |
||
181 | |||
182 | /** |
||
183 | * Return's the PK to create the product => variant relation. |
||
184 | * |
||
185 | * @return integer The PK to create the relation with |
||
186 | */ |
||
187 | protected function getLastPrimaryKey() |
||
191 | |||
192 | /** |
||
193 | * Return the link type ID for the passed link type code. |
||
194 | * |
||
195 | * @param string $linkTypeCode The link type code to return the link type ID for |
||
196 | * |
||
197 | * @return integer The mapped link type ID |
||
198 | * @throws \TechDivision\Import\Product\Exceptions\MapLinkTypeCodeToIdException Is thrown if the link type code is |
||
199 | * not mapped yet |
||
200 | */ |
||
201 | protected function mapLinkTypeCodeToLinkTypeId($linkTypeCode) |
||
205 | } |
||
206 |
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: