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() |
||
146 | |||
147 | /** |
||
148 | * Delete not exists import links from database. |
||
149 | * |
||
150 | * @param int $parentProductId The ID of the parent product |
||
151 | * @param string $linkTypeCode The link type code to prepare the artefacts for |
||
152 | * @param array $childData The array of variants |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | protected function doCleanUp($parentProductId, $linkTypeCode, array $childData) |
||
188 | |||
189 | /** |
||
190 | * Return's the PK to create the product => variant relation. |
||
191 | * |
||
192 | * @return integer The PK to create the relation with |
||
193 | */ |
||
194 | protected function getLastPrimaryKey() |
||
198 | |||
199 | /** |
||
200 | * Return the link type ID for the passed link type code. |
||
201 | * |
||
202 | * @param string $linkTypeCode The link type code to return the link type ID for |
||
203 | * |
||
204 | * @return integer The mapped link type ID |
||
205 | * @throws \TechDivision\Import\Product\Exceptions\MapLinkTypeCodeToIdException Is thrown if the link type code is |
||
206 | * not mapped yet |
||
207 | */ |
||
208 | protected function mapLinkTypeCodeToLinkTypeId($linkTypeCode) |
||
212 | } |
||
213 |
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: