1 | <?php |
||
43 | class UrlKeyObserver extends AbstractProductImportObserver |
||
44 | { |
||
45 | |||
46 | /** |
||
47 | * The trait that provides string => URL key conversion functionality. |
||
48 | * |
||
49 | * @var \TechDivision\Import\Utils\Filter\UrlKeyFilterTrait |
||
50 | */ |
||
51 | use UrlKeyFilterTrait; |
||
52 | |||
53 | /** |
||
54 | * The URL key utility instance. |
||
55 | * |
||
56 | * @var \TechDivision\Import\Utils\UrlKeyUtilInterface |
||
57 | */ |
||
58 | protected $urlKeyUtil; |
||
59 | |||
60 | /** |
||
61 | * The product bunch processor instance. |
||
62 | * |
||
63 | * @var \TechDivision\Import\Product\Services\ProductBunchProcessorInterface |
||
64 | */ |
||
65 | protected $productBunchProcessor; |
||
66 | |||
67 | /** |
||
68 | * Initialize the observer with the passed product bunch processor and filter instance. |
||
69 | * |
||
70 | * @param \TechDivision\Import\Product\Services\ProductBunchProcessorInterface $productBunchProcessor The product bunch processor instance |
||
71 | * @param \Zend\Filter\FilterInterface $convertLiteralUrlFilter The URL filter instance |
||
72 | * @param \TechDivision\Import\Utils\UrlKeyUtilInterface $urlKeyUtil The URL key utility instance |
||
73 | */ |
||
74 | public function __construct( |
||
83 | |||
84 | /** |
||
85 | * Return's the product bunch processor instance. |
||
86 | * |
||
87 | * @return \TechDivision\Import\Product\Services\ProductBunchProcessorInterface The product bunch processor instance |
||
88 | */ |
||
89 | protected function getProductBunchProcessor() : ProductBunchProcessorInterface |
||
93 | |||
94 | /** |
||
95 | * Returns the URL key utility instance. |
||
96 | * |
||
97 | * @return \TechDivision\Import\Utils\UrlKeyUtilInterface The URL key utility instance |
||
98 | */ |
||
99 | protected function getUrlKeyUtil() : UrlKeyUtilInterface |
||
103 | |||
104 | /** |
||
105 | * Process the observer's business logic. |
||
106 | * |
||
107 | * @return void |
||
108 | * @throws \Exception Is thrown, if either column "url_key" or "name" have a value set |
||
109 | */ |
||
110 | protected function process() |
||
160 | |||
161 | /** |
||
162 | * Extract's the category from the comma separeted list of categories |
||
163 | * in column `categories` and return's an array with their URL paths. |
||
164 | * |
||
165 | * @return string[] Array with the URL paths of the categories found in column `categories` |
||
166 | */ |
||
167 | protected function getUrlPaths() |
||
193 | |||
194 | /** |
||
195 | * Recursively resolves an array with the store view specific |
||
196 | * URL paths of the passed category. |
||
197 | * |
||
198 | * @param array $urlPaths The array to append the URL paths to |
||
199 | * @param array $category The category to resolve the list with URL paths |
||
200 | * @param string $storeViewCode The store view code to resolve the URL paths for |
||
201 | * @param bool $directRelation the flag whether or not the passed category is a direct relation to the product and has to added to the list |
||
202 | * |
||
203 | * @return void |
||
204 | */ |
||
205 | protected function resolveUrlPaths(array &$urlPaths, array $category, string $storeViewCode, bool $directRelation = true) |
||
234 | |||
235 | /** |
||
236 | * Temporarily persist's the IDs of the passed product. |
||
237 | * |
||
238 | * @param array $product The product to temporarily persist the IDs for |
||
239 | * |
||
240 | * @return void |
||
241 | */ |
||
242 | protected function setIds(array $product) |
||
246 | |||
247 | /** |
||
248 | * Set's the ID of the product that has been created recently. |
||
249 | * |
||
250 | * @param string $lastEntityId The entity ID |
||
251 | * |
||
252 | * @return void |
||
253 | */ |
||
254 | protected function setLastEntityId($lastEntityId) |
||
258 | |||
259 | /** |
||
260 | * Return's the PK to of the product. |
||
261 | * |
||
262 | * @return integer The PK to create the relation with |
||
263 | */ |
||
264 | protected function getPrimaryKey() |
||
268 | |||
269 | /** |
||
270 | * Load's and return's the product with the passed SKU. |
||
271 | * |
||
272 | * @param string $sku The SKU of the product to load |
||
273 | * |
||
274 | * @return array The product |
||
275 | */ |
||
276 | protected function loadProduct($sku) |
||
280 | |||
281 | /** |
||
282 | * Load's and return's the url_key with the passed primary ID. |
||
283 | * |
||
284 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to load the URL key |
||
285 | * @param int $primaryKeyId The ID from product |
||
286 | * |
||
287 | * @return string|null url_key or null |
||
288 | */ |
||
289 | protected function loadUrlKey(UrlKeyAwareSubjectInterface $subject, $primaryKeyId) |
||
293 | |||
294 | /** |
||
295 | * Return's the category with the passed path. |
||
296 | * |
||
297 | * @param string $path The path of the category to return |
||
298 | * @param string $storeViewCode The code of a store view, defaults to admin |
||
299 | * |
||
300 | * @return array The category |
||
301 | */ |
||
302 | protected function getCategoryByPath($path, $storeViewCode = StoreViewCodes::ADMIN) |
||
306 | |||
307 | /** |
||
308 | * Make's the passed URL key unique by adding the next number to the end. |
||
309 | * |
||
310 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for |
||
311 | * @param string $urlKey The URL key to make unique |
||
312 | * @param array $urlPaths The URL paths to make unique |
||
313 | * |
||
314 | * @return string The unique URL key |
||
315 | */ |
||
316 | protected function makeUnique(UrlKeyAwareSubjectInterface $subject, string $urlKey, array $urlPaths = array()) |
||
320 | |||
321 | /** |
||
322 | * Return's the root category for the actual view store. |
||
323 | * |
||
324 | * @return array The store's root category |
||
325 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
326 | */ |
||
327 | protected function getRootCategory() |
||
331 | |||
332 | /** |
||
333 | * Return's the category with the passed ID. |
||
334 | * |
||
335 | * @param integer $categoryId The ID of the category to return |
||
336 | * @param string $storeViewCode The code of a store view, defaults to "admin" |
||
337 | * |
||
338 | * @return array The category data |
||
339 | */ |
||
340 | protected function getCategory($categoryId, $storeViewCode = StoreViewCodes::ADMIN) |
||
344 | } |
||
345 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.