1 | <?php |
||
36 | class LinkSubject extends AbstractProductSubject |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The temporary persisted last link ID. |
||
41 | * |
||
42 | * @var integer |
||
43 | */ |
||
44 | protected $lastLinkId; |
||
45 | |||
46 | /** |
||
47 | * The available link types. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $linkTypes = array(); |
||
52 | |||
53 | /** |
||
54 | * The available link attributes. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $linkAttributes = array(); |
||
59 | |||
60 | /** |
||
61 | * The mapping for the SKUs to the created entity IDs. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $skuEntityIdMapping = array(); |
||
66 | |||
67 | /** |
||
68 | * Intializes the previously loaded global data for exactly one variants. |
||
69 | * |
||
70 | * @return void |
||
71 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
72 | */ |
||
73 | public function setUp() |
||
92 | |||
93 | /** |
||
94 | * Temporary persist the last link ID. |
||
95 | * |
||
96 | * @param integer $lastLinkId The last link ID |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | public function setLastLinkId($lastLinkId) |
||
104 | |||
105 | /** |
||
106 | * Load the temporary persisted the last link ID. |
||
107 | * |
||
108 | * @return integer The last link ID |
||
109 | */ |
||
110 | public function getLastLinkId() |
||
114 | |||
115 | /** |
||
116 | * Return the entity ID for the passed SKU. |
||
117 | * |
||
118 | * @param string $sku The SKU to return the entity ID for |
||
119 | * |
||
120 | * @return integer The mapped entity ID |
||
121 | * @throws \Exception Is thrown if the SKU is not mapped yet |
||
122 | */ |
||
123 | public function mapSkuToEntityId($sku) |
||
134 | |||
135 | /** |
||
136 | * Return's the link type ID for the passed link type code. |
||
137 | * |
||
138 | * @param string $linkTypeCode The link type code to return the link type ID for |
||
139 | * |
||
140 | * @return integer The mapped link type ID |
||
141 | * @throws \Exception Is thrown if the link type code is not mapped yet |
||
142 | */ |
||
143 | public function mapLinkTypeCodeToLinkTypeId($linkTypeCode) |
||
154 | |||
155 | /** |
||
156 | * Return's the link attribute for the passed link type ID and attribute code. |
||
157 | * |
||
158 | * @param integer $linkTypeId The link type |
||
159 | * @param string $attributeCode The attribute code |
||
160 | * |
||
161 | * @return array The link attribute |
||
162 | */ |
||
163 | public function getProductLinkAttribute($linkTypeId, $attributeCode) |
||
176 | |||
177 | /** |
||
178 | * Load's the link with the passed product/linked product/link type ID. |
||
179 | * |
||
180 | * @param integer $productId The product ID of the link to load |
||
181 | * @param integer $linkedProductId The linked product ID of the link to load |
||
182 | * @param integer $linkTypeId The link type ID of the product to load |
||
183 | * |
||
184 | * @return array The link |
||
185 | */ |
||
186 | public function loadProductLink($productId, $linkedProductId, $linkTypeId) |
||
190 | |||
191 | /** |
||
192 | * Return's the product link attribute integer value with the passed product link attribute/link ID. |
||
193 | * |
||
194 | * @param integer $productLinkAttributeId The product link attribute ID of the attributes |
||
195 | * @param integer $linkId The link ID of the attribute |
||
196 | * |
||
197 | * @return array The product link attribute integer value |
||
198 | */ |
||
199 | public function loadProductLinkAttributeInt($productLinkAttributeId, $linkId) |
||
203 | |||
204 | /** |
||
205 | * Persist's the passed product link data and return's the ID. |
||
206 | * |
||
207 | * @param array $productLink The product link data to persist |
||
208 | * |
||
209 | * @return string The ID of the persisted entity |
||
210 | */ |
||
211 | public function persistProductLink($productLink) |
||
215 | |||
216 | /** |
||
217 | * Persist's the passed product link attribute integer data. |
||
218 | * |
||
219 | * @param array $productLinkAttributeInt The product link attribute integer data to persist |
||
220 | * |
||
221 | * @return string The ID of the persisted entity |
||
222 | */ |
||
223 | public function persistProductLinkAttributeInt($productLinkAttributeInt) |
||
227 | } |
||
228 |
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: