1 | <?php |
||
44 | class UrlKeyObserver extends AbstractProductImportObserver |
||
45 | { |
||
46 | |||
47 | /** |
||
48 | * The trait that provides string => URL key conversion functionality. |
||
49 | * |
||
50 | * @var \TechDivision\Import\Utils\Filter\UrlKeyFilterTrait |
||
51 | */ |
||
52 | use UrlKeyFilterTrait; |
||
53 | |||
54 | /** |
||
55 | * The URL key utility instance. |
||
56 | * |
||
57 | * @var \TechDivision\Import\Utils\UrlKeyUtilInterface |
||
58 | */ |
||
59 | protected $urlKeyUtil; |
||
60 | |||
61 | /** |
||
62 | * The product bunch processor instance. |
||
63 | * |
||
64 | * @var \TechDivision\Import\Product\Services\ProductBunchProcessorInterface |
||
65 | */ |
||
66 | protected $productBunchProcessor; |
||
67 | |||
68 | /** |
||
69 | * The reverse sequence generator instance. |
||
70 | * |
||
71 | * @var \TechDivision\Import\Utils\Generators\GeneratorInterface |
||
72 | */ |
||
73 | protected $reverseSequenceGenerator; |
||
74 | |||
75 | /** |
||
76 | * Initialize the observer with the passed product bunch processor and filter instance. |
||
77 | * |
||
78 | * @param \TechDivision\Import\Product\Services\ProductBunchProcessorInterface $productBunchProcessor The product bunch processor instance |
||
79 | * @param \Zend\Filter\FilterInterface $convertLiteralUrlFilter The URL filter instance |
||
80 | * @param \TechDivision\Import\Utils\UrlKeyUtilInterface $urlKeyUtil The URL key utility instance |
||
81 | * @param \TechDivision\Import\Utils\Generators\GeneratorInterface $reverseSequenceGenerator The reverse sequence generator instance |
||
82 | */ |
||
83 | public function __construct( |
||
84 | ProductBunchProcessorInterface $productBunchProcessor, |
||
85 | FilterInterface $convertLiteralUrlFilter, |
||
86 | UrlKeyUtilInterface $urlKeyUtil, |
||
87 | GeneratorInterface $reverseSequenceGenerator |
||
88 | ) { |
||
89 | $this->productBunchProcessor = $productBunchProcessor; |
||
90 | $this->convertLiteralUrlFilter = $convertLiteralUrlFilter; |
||
91 | $this->urlKeyUtil = $urlKeyUtil; |
||
92 | $this->reverseSequenceGenerator = $reverseSequenceGenerator; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Return's the product bunch processor instance. |
||
97 | * |
||
98 | * @return \TechDivision\Import\Product\Services\ProductBunchProcessorInterface The product bunch processor instance |
||
99 | */ |
||
100 | protected function getProductBunchProcessor() : ProductBunchProcessorInterface |
||
101 | { |
||
102 | return $this->productBunchProcessor; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Returns the URL key utility instance. |
||
107 | * |
||
108 | * @return \TechDivision\Import\Utils\UrlKeyUtilInterface The URL key utility instance |
||
109 | */ |
||
110 | protected function getUrlKeyUtil() : UrlKeyUtilInterface |
||
111 | { |
||
112 | return $this->urlKeyUtil; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Returns the reverse sequence generator instance. |
||
117 | * |
||
118 | * @return \TechDivision\Import\Utils\Generators\GeneratorInterface The reverse sequence generator |
||
119 | */ |
||
120 | protected function getReverseSequenceGenerator() : GeneratorInterface |
||
124 | |||
125 | /** |
||
126 | * Process the observer's business logic. |
||
127 | * |
||
128 | * @return void |
||
129 | * @throws \Exception Is thrown, if either column "url_key" or "name" have a value set |
||
130 | */ |
||
131 | protected function process() |
||
183 | |||
184 | /** |
||
185 | * Extract's the category from the comma separeted list of categories |
||
186 | * in column `categories` and return's an array with their URL paths. |
||
187 | * |
||
188 | * @return string[] Array with the URL paths of the categories found in column `categories` |
||
189 | */ |
||
190 | protected function getUrlPaths() |
||
216 | |||
217 | /** |
||
218 | * Recursively resolves an array with the store view specific |
||
219 | * URL paths of the passed category. |
||
220 | * |
||
221 | * @param array $urlPaths The array to append the URL paths to |
||
222 | * @param array $category The category to resolve the list with URL paths |
||
223 | * @param string $storeViewCode The store view code to resolve the URL paths for |
||
224 | * @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 |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | protected function resolveUrlPaths(array &$urlPaths, array $category, string $storeViewCode, bool $directRelation = true) |
||
257 | |||
258 | /** |
||
259 | * Temporarily persist's the IDs of the passed product. |
||
260 | * |
||
261 | * @param array $product The product to temporarily persist the IDs for |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | protected function setIds(array $product) |
||
269 | |||
270 | /** |
||
271 | * Set's the ID of the product that has been created recently. |
||
272 | * |
||
273 | * @param string $lastEntityId The entity ID |
||
274 | * |
||
275 | * @return void |
||
276 | */ |
||
277 | protected function setLastEntityId($lastEntityId) |
||
281 | |||
282 | /** |
||
283 | * Return's the PK to of the product. |
||
284 | * |
||
285 | * @return integer The PK to create the relation with |
||
286 | */ |
||
287 | protected function getPrimaryKey() |
||
291 | |||
292 | /** |
||
293 | * Load's and return's the product with the passed SKU. |
||
294 | * |
||
295 | * @param string $sku The SKU of the product to load |
||
296 | * |
||
297 | * @return array The product |
||
298 | */ |
||
299 | protected function loadProduct($sku) |
||
303 | |||
304 | /** |
||
305 | * Load's and return's the url_key with the passed primary ID. |
||
306 | * |
||
307 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to load the URL key |
||
308 | * @param int $primaryKeyId The ID from product |
||
309 | * |
||
310 | * @return string|null url_key or null |
||
311 | */ |
||
312 | protected function loadUrlKey(UrlKeyAwareSubjectInterface $subject, $primaryKeyId) |
||
316 | |||
317 | /** |
||
318 | * Return's the category with the passed path. |
||
319 | * |
||
320 | * @param string $path The path of the category to return |
||
321 | * @param string $storeViewCode The code of a store view, defaults to admin |
||
322 | * |
||
323 | * @return array The category |
||
324 | */ |
||
325 | protected function getCategoryByPath($path, $storeViewCode = StoreViewCodes::ADMIN) |
||
329 | |||
330 | /** |
||
331 | * Make's the passed URL key unique by adding the next number to the end. |
||
332 | * |
||
333 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for |
||
334 | * @param array $entity The entity to make the URL key unique for |
||
335 | * @param string $urlKey The URL key to make unique |
||
336 | * @param array $urlPaths The URL paths to make unique |
||
337 | * |
||
338 | * @return string The unique URL key |
||
339 | */ |
||
340 | protected function makeUnique(UrlKeyAwareSubjectInterface $subject, array $entity, string $urlKey, array $urlPaths = array()) |
||
344 | |||
345 | /** |
||
346 | * Return's the root category for the actual view store. |
||
347 | * |
||
348 | * @return array The store's root category |
||
349 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
350 | */ |
||
351 | protected function getRootCategory() |
||
355 | |||
356 | /** |
||
357 | * Return's the category with the passed ID. |
||
358 | * |
||
359 | * @param integer $categoryId The ID of the category to return |
||
360 | * @param string $storeViewCode The code of a store view, defaults to "admin" |
||
361 | * |
||
362 | * @return array The category data |
||
363 | */ |
||
364 | protected function getCategory($categoryId, $storeViewCode = StoreViewCodes::ADMIN) |
||
368 | } |
||
369 |
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.