Conditions | 9 |
Paths | 12 |
Total Lines | 58 |
Code Lines | 37 |
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); |
||
91 | INNER JOIN sales_channel |
||
92 | ON domains.sales_channel_id = sales_channel.id |
||
93 | AND sales_channel.active = 1' |
||
94 | ); |
||
95 | |||
96 | if ($domains === []) { |
||
97 | return []; |
||
98 | } |
||
99 | |||
100 | $salesChannelTemplates = $this->connection->fetchAllKeyValue( |
||
101 | 'SELECT LOWER(HEX(sales_channel_id)) as sales_channel_id, template |
||
102 | FROM seo_url_template |
||
103 | WHERE route_name LIKE :route', |
||
104 | ['route' => $routeName] |
||
105 | ); |
||
106 | |||
107 | if (!\array_key_exists('', $salesChannelTemplates)) { |
||
108 | throw new \RuntimeException('Default templates not configured'); |
||
109 | } |
||
110 | |||
111 | $default = (string) $salesChannelTemplates['']; |
||
112 | |||
113 | $result = []; |
||
114 | foreach ($domains as $domain) { |
||
115 | $salesChannelId = $domain['salesChannelId']; |
||
116 | |||
117 | $result[] = [ |
||
118 | 'salesChannelId' => $salesChannelId, |
||
119 | 'languageId' => $domain['languageId'], |
||
120 | 'template' => $salesChannelTemplates[$salesChannelId] ?? $default, |
||
121 | ]; |
||
122 | } |
||
123 | |||
124 | return $result; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return array<string, array<string>> |
||
129 | */ |
||
130 | private function fetchLanguageChains(Context $context): array |
||
131 | { |
||
132 | $languages = $this->languageRepository->search(new Criteria(), $context)->getEntities()->getElements(); |
||
133 | |||
134 | $languageChains = []; |
||
135 | foreach ($languages as $language) { |
||
136 | $languageId = $language->getId(); |
||
137 | $languageChains[$languageId] = array_filter([ |
||
138 | $languageId, |
||
139 | $language->getParentId(), |
||
140 | Defaults::LANGUAGE_SYSTEM, |
||
141 | ]); |
||
142 | } |
||
143 | |||
144 | return $languageChains; |
||
145 | } |
||
146 | } |
||
147 |