| Conditions | 10 |
| Paths | 32 |
| Total Lines | 64 |
| Code Lines | 38 |
| 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); |
||
| 136 | public function load(string $token, ?string $salesChannelId = null, ?string $customerId = null): array |
||
| 137 | { |
||
| 138 | if (Feature::isActive('FEATURE_NEXT_10058')) { |
||
| 139 | $qb = $this->connection->createQueryBuilder(); |
||
| 140 | |||
| 141 | $qb->select('*'); |
||
| 142 | $qb->from('sales_channel_api_context'); |
||
| 143 | |||
| 144 | if ($salesChannelId !== null) { |
||
| 145 | $qb->where('sales_channel_id = :salesChannelId'); |
||
| 146 | $qb->setParameter(':salesChannelId', Uuid::fromHexToBytes($salesChannelId)); |
||
| 147 | |||
| 148 | if ($customerId !== null) { |
||
| 149 | $qb->andWhere('token = :token OR customer_id = :customerId'); |
||
| 150 | $qb->setParameter(':token', $token); |
||
| 151 | $qb->setParameter(':customerId', Uuid::fromHexToBytes($customerId)); |
||
| 152 | $qb->setMaxResults(2); |
||
| 153 | } else { |
||
| 154 | $qb->andWhere('token = :token'); |
||
| 155 | $qb->setParameter(':token', $token); |
||
| 156 | $qb->setMaxResults(1); |
||
| 157 | } |
||
| 158 | } else { |
||
| 159 | $qb->where('token = :token'); |
||
| 160 | $qb->setParameter(':token', $token); |
||
| 161 | $qb->setMaxResults(1); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** @var ResultStatement $statement */ |
||
| 165 | $statement = $qb->execute(); |
||
| 166 | |||
| 167 | if (!$statement instanceof ResultStatement) { |
||
|
|
|||
| 168 | return []; |
||
| 169 | } |
||
| 170 | |||
| 171 | $data = $statement->fetchAll(); |
||
| 172 | |||
| 173 | if (empty($data)) { |
||
| 174 | return []; |
||
| 175 | } |
||
| 176 | |||
| 177 | $customerContext = $salesChannelId && $customerId ? $this->getCustomerContext($data, $salesChannelId, $customerId) : null; |
||
| 178 | |||
| 179 | $context = $customerContext ?? array_shift($data); |
||
| 180 | |||
| 181 | $payload = array_filter(json_decode($context['payload'], true)); |
||
| 182 | |||
| 183 | if ($customerId) { |
||
| 184 | $payload['token'] = $context['token']; |
||
| 185 | } |
||
| 186 | |||
| 187 | return $payload; |
||
| 188 | } |
||
| 189 | |||
| 190 | $parameter = $this->connection->fetchColumn( |
||
| 191 | 'SELECT `payload` FROM sales_channel_api_context WHERE token = :token', |
||
| 192 | ['token' => $token] |
||
| 193 | ); |
||
| 194 | |||
| 195 | if (!$parameter) { |
||
| 196 | return []; |
||
| 197 | } |
||
| 198 | |||
| 199 | return array_filter(json_decode($parameter, true)); |
||
| 200 | } |
||
| 247 |