GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BaseQueryTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 17
dl 0
loc 42
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addOrderField() 0 22 5
A addOrder() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Doctrine\Manager\ORM;
13
14
use Doctrine\ORM\QueryBuilder;
15
use InvalidArgumentException;
16
17
trait BaseQueryTrait
18
{
19
    /**
20
     * @param array<int|string, string> $sort
21
     * @param array<string, string>     $aliasMapping
22
     */
23
    final protected function addOrder(QueryBuilder $builder, array $sort, string $defaultAlias, array $aliasMapping = [], string $defaultOrder = 'asc'): QueryBuilder
24
    {
25
        foreach ($sort as $field => $order) {
26
            if (\is_int($field)) {
27
                $field = $order;
28
                $order = $defaultOrder;
29
            }
30
31
            $this->addOrderField($builder, $defaultAlias, $field, $order, $aliasMapping);
32
        }
33
34
        return $builder;
35
    }
36
37
    private function addOrderField(QueryBuilder $builder, string $table, string $field, string $order, array $aliasMapping = []): void
38
    {
39
        $fieldSpl = explode('.', $field);
40
41
        if (\count($fieldSpl) > 2) {
42
            throw new InvalidArgumentException(sprintf('The fieldname "%s" cannot contain more than one dot', $field));
43
        }
44
45
        // Map entity to table name
46
        if (2 === \count($fieldSpl)) {
47
            [$table, $field] = $fieldSpl;
48
49
            foreach ($aliasMapping as $k => $v) {
50
                if ($fieldSpl[0] === $k) {
51
                    $table = $v;
52
53
                    break;
54
                }
55
            }
56
        }
57
58
        $builder->addOrderBy($table.'.'.$field, $order);
59
    }
60
}
61