Completed
Pull Request — 1.5 (#761)
by Paweł
17:05
created

PackageRepository::applyCriteria()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 25

Duplication

Lines 19
Ratio 76 %

Importance

Changes 0
Metric Value
dl 19
loc 25
rs 9.2088
c 0
b 0
f 0
cc 5
nc 4
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2019 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2019 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Repository;
18
19
use Doctrine\ORM\QueryBuilder;
20
use SWP\Bundle\BridgeBundle\Doctrine\ORM\PackageRepository as BasePackageRepository;
21
use SWP\Component\Common\Criteria\Criteria;
22
23
class PackageRepository extends BasePackageRepository implements PackageRepositoryInterface
24
{
25
    public function applyCriteria(QueryBuilder $queryBuilder, Criteria $criteria, string $alias)
26
    {
27 View Code Duplication
        if ($criteria->has('authors')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
            $queryBuilder->leftJoin($alias.'.authors', 'au');
29
            $orX = $queryBuilder->expr()->orX();
30
            foreach ((array) $criteria->get('authors') as $value) {
31
                $orX->add($queryBuilder->expr()->eq('au.name', $queryBuilder->expr()->literal($value)));
32
            }
33
34
            $queryBuilder->andWhere($orX);
35
            $criteria->remove('authors');
36
        }
37
38 View Code Duplication
        if ($criteria->has('statuses')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
            $orX = $queryBuilder->expr()->orX();
40
            foreach ((array) $criteria->get('statuses') as $value) {
41
                $orX->add($queryBuilder->expr()->eq($alias.'.status', $queryBuilder->expr()->literal($value)));
42
            }
43
44
            $queryBuilder->andWhere($orX);
45
            $criteria->remove('statuses');
46
        }
47
48
        parent::applyCriteria($queryBuilder, $criteria, $alias);
49
    }
50
}
51