| Conditions | 6 |
| Paths | 5 |
| Total Lines | 60 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 32 | public function resolve(string $languageId, string $salesChannelId, string $pathInfo): array |
||
| 33 | { |
||
| 34 | $seoPathInfo = ltrim($pathInfo, '/'); |
||
| 35 | |||
| 36 | $query = (new QueryBuilder($this->connection)) |
||
| 37 | ->select('id', 'path_info pathInfo', 'is_canonical isCanonical', 'sales_channel_id salesChannelId') |
||
| 38 | ->from('seo_url') |
||
| 39 | ->where('language_id = :language_id') |
||
| 40 | ->andWhere('(sales_channel_id = :sales_channel_id OR sales_channel_id IS NULL)') |
||
| 41 | ->andWhere('seo_path_info = :seoPath') |
||
| 42 | ->setParameter('language_id', Uuid::fromHexToBytes($languageId)) |
||
| 43 | ->setParameter('sales_channel_id', Uuid::fromHexToBytes($salesChannelId)) |
||
| 44 | ->setParameter('seoPath', $seoPathInfo); |
||
| 45 | |||
| 46 | $query->setTitle('seo-url::resolve'); |
||
| 47 | |||
| 48 | $seoPaths = $query->executeQuery()->fetchAllAssociative(); |
||
| 49 | |||
| 50 | // sort seoPaths by filled salesChannelId, save file sort on SQL server |
||
| 51 | usort($seoPaths, static function ($a, $b) { |
||
| 52 | if ($a['salesChannelId'] === null) { |
||
| 53 | return 1; |
||
| 54 | } |
||
| 55 | if ($b['salesChannelId'] === null) { |
||
| 56 | return -1; |
||
| 57 | } |
||
| 58 | |||
| 59 | return 0; |
||
| 60 | }); |
||
| 61 | |||
| 62 | $seoPath = $seoPaths[0] ?? ['pathInfo' => $seoPathInfo, 'isCanonical' => false]; |
||
| 63 | |||
| 64 | if (!$seoPath['isCanonical']) { |
||
| 65 | $query = $this->connection->createQueryBuilder() |
||
| 66 | ->select('path_info pathInfo', 'seo_path_info seoPathInfo') |
||
| 67 | ->from('seo_url') |
||
| 68 | ->where('language_id = :language_id') |
||
| 69 | ->andWhere('sales_channel_id = :sales_channel_id') |
||
| 70 | ->andWhere('path_info = :pathInfo') |
||
| 71 | ->andWhere('is_canonical = 1') |
||
| 72 | ->setMaxResults(1) |
||
| 73 | ->setParameter('language_id', Uuid::fromHexToBytes($languageId)) |
||
| 74 | ->setParameter('sales_channel_id', Uuid::fromHexToBytes($salesChannelId)) |
||
| 75 | ->setParameter('pathInfo', '/' . ltrim((string) $seoPath['pathInfo'], '/')); |
||
| 76 | |||
| 77 | // we only have an id when the hit seo url was not a canonical url, save the one filter condition |
||
| 78 | if (isset($seoPath['id'])) { |
||
| 79 | $query->andWhere('id != :id') |
||
| 80 | ->setParameter('id', $seoPath['id']); |
||
| 81 | } |
||
| 82 | |||
| 83 | $canonical = $query->executeQuery()->fetchAssociative(); |
||
| 84 | if ($canonical) { |
||
| 85 | $seoPath['canonicalPathInfo'] = '/' . ltrim((string) $canonical['seoPathInfo'], '/'); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $seoPath['pathInfo'] = '/' . ltrim((string) $seoPath['pathInfo'], '/'); |
||
| 90 | |||
| 91 | return $seoPath; |
||
| 92 | } |
||
| 94 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths