1 | <?php |
||
36 | class UrlKeyUtil implements UrlKeyUtilInterface |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The URL key aware processor instance. |
||
41 | * |
||
42 | * \TechDivision\Import\Services\UrlKeyAwareProcessorInterface |
||
43 | */ |
||
44 | protected $urlKeyAwareProcessor; |
||
45 | |||
46 | /** |
||
47 | * The array with the entity type and store view specific suffixes. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $suffixes = array(); |
||
52 | |||
53 | /** |
||
54 | * The array with the entity type code > configuration key mapping. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $entityTypeCodeToConfigKeyMapping = array( |
||
59 | EntityTypeCodes::CATALOG_PRODUCT => CoreConfigDataKeys::CATALOG_SEO_PRODUCT_URL_SUFFIX, |
||
60 | EntityTypeCodes::CATALOG_CATEGORY => CoreConfigDataKeys::CATALOG_SEO_CATEGORY_URL_SUFFIX |
||
61 | ); |
||
62 | |||
63 | /** |
||
64 | * Construct a new instance. |
||
65 | * |
||
66 | * @param \TechDivision\Import\Services\UrlKeyAwareProcessorInterface $urlKeyAwareProcessor The URL key aware processor instance |
||
67 | * @param \TechDivision\Import\Loaders\LoaderInterface $coreConfigDataLoader The core config data loader instance |
||
68 | * @param \TechDivision\Import\Loaders\LoaderInterface $storeIdLoader The core config data loader instance |
||
69 | */ |
||
70 | public function __construct( |
||
93 | |||
94 | /** |
||
95 | * Returns the URL key aware processor instance. |
||
96 | * |
||
97 | * @return \TechDivision\Import\Services\UrlKeyAwareProcessorInterface The processor instance |
||
98 | */ |
||
99 | protected function getUrlKeyAwareProcessor() |
||
103 | |||
104 | /** |
||
105 | * Load's and return's the URL rewrite for the given request path and store ID |
||
106 | * |
||
107 | * @param string $requestPath The request path to load the URL rewrite for |
||
108 | * @param int $storeId The store ID to load the URL rewrite for |
||
109 | * |
||
110 | * @return string|null The URL rewrite found for the given request path and store ID |
||
111 | */ |
||
112 | protected function loadUrlRewriteByRequestPathAndStoreId(string $requestPath, int $storeId) |
||
116 | |||
117 | /** |
||
118 | * Make's the passed URL key unique by adding/raising a number to the end. |
||
119 | * |
||
120 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for |
||
121 | * @param array $entity The entity to make the URL key unique for |
||
122 | * @param string $urlKey The URL key to make unique |
||
123 | * @param string|null $urlPath The URL path to make unique (only used for categories) |
||
124 | * |
||
125 | * @return string The unique URL key |
||
126 | */ |
||
127 | protected function doMakeUnique(UrlKeyAwareSubjectInterface $subject, array $entity, string $urlKey, string $urlPath = null) : string |
||
211 | |||
212 | /** |
||
213 | * Make's the passed URL key unique by adding the next number to the end. |
||
214 | * |
||
215 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for |
||
216 | * @param array $entity The entity to make the URL key unique for |
||
217 | * @param string $urlKey The URL key to make unique |
||
218 | * @param array $urlPaths The URL paths to make unique |
||
219 | * |
||
220 | * @return string The unique URL key |
||
221 | */ |
||
222 | public function makeUnique(UrlKeyAwareSubjectInterface $subject, array $entity, string $urlKey, array $urlPaths = array()) : string |
||
223 | { |
||
224 | |||
225 | // iterate over the passed URL paths |
||
226 | // and try to find a unique URL key |
||
227 | for ($i = sizeof($urlPaths) > 0 ? 0 : -1; $i < sizeof($urlPaths); $i++) { |
||
228 | // try to make the URL key unique for the given URL path |
||
229 | $proposedUrlKey = $this->doMakeUnique($subject, $entity, $urlKey, isset($urlPaths[$i]) ? $urlPaths[$i] : null); |
||
230 | |||
231 | // if the URL key is NOT the same as the passed one or with the parent URL path |
||
232 | // it can NOT be used, so we've to persist it temporarily and try it again for |
||
233 | // all the other URL paths until we found one that works with every URL path |
||
234 | if ($urlKey !== $proposedUrlKey) { |
||
235 | // temporarily persist the URL key |
||
236 | $urlKey = $proposedUrlKey; |
||
237 | // reset the counter and restart the |
||
238 | // iteration with the first URL path |
||
239 | $i = -2; |
||
240 | } |
||
241 | } |
||
242 | |||
243 | // return the unique URL key |
||
244 | return $urlKey; |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Load the url_key if exists |
||
249 | * |
||
250 | * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for |
||
251 | * @param int $primaryKeyId The ID from category or product |
||
252 | * |
||
253 | * @return string|null The URL key |
||
254 | */ |
||
255 | public function loadUrlKey(UrlKeyAwareSubjectInterface $subject, $primaryKeyId) |
||
278 | } |
||
279 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.