Completed
Push — EZP-31084-part2-poc ( f20bda )
by André
19:16
created

UserMetadata::handle()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 64
rs 8.7853
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Legacy\Content\Query\CriterionHandler;
10
11
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
12
use Doctrine\DBAL\Query\QueryBuilder;
13
use eZ\Publish\Core\Persistence\Legacy\Content\Query\CriteriaConverter;
14
use RuntimeException;
15
16
class UserMetadata extends Base
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function accept(Criterion $criterion): bool
22
    {
23
        return $criterion instanceof Criterion\SectionId;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function handle(CriteriaConverter $converter, QueryBuilder $query, Criterion $criterion): string
30
    {
31
        $expr = $query->expr();
0 ignored issues
show
Unused Code introduced by
$expr is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
32
        /*return $expr->in(
33
            'content.section_id',
34
            $query->createNamedParameter((array)$criterion->value, Connection::PARAM_INT_ARRAY)
35
        );*/
36
37
        /* @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion\UserMetadata $criterion */
38
        switch ($criterion->target) {
39
40
            case Criterion\UserMetadata::MODIFIER:
41
                $this->addInnerJoinIfNeeded(
42
                    $query,
43
                    'content',
44
                    'ezcontentobject_version',
45
                    'version',
46
                    'version.contentobject_id = content.id AND version.version = content.current_version'
47
                );
48
49
                return $this->operateInt($query, 'version.creator_id', $criterion);
50
51
52
            // @TODO Needed for permissions
53
            /*case Criterion\UserMetadata::GROUP:
54
                $subSelect = $query->subSelect();
55
                $subSelect
56
                    ->select(
57
                        $this->dbHandler->quoteColumn('contentobject_id', 't1')
58
                    )->from(
59
                        $query->alias(
60
                            $this->dbHandler->quoteTable('ezcontentobject_tree'),
61
                            't1'
62
                        )
63
                    )->innerJoin(
64
                        $query->alias(
65
                            $this->dbHandler->quoteTable('ezcontentobject_tree'),
66
                            't2'
67
                        ),
68
                        $query->expr->like(
69
                            't1.path_string',
70
                            $query->expr->concat(
71
                                't2.path_string',
72
                                $query->bindValue('%')
73
                            )
74
                        )
75
                    )->where(
76
                        $query->expr->in(
77
                            $this->dbHandler->quoteColumn('contentobject_id', 't2'),
78
                            $criterion->value
79
                        )
80
                    );
81
82
                return $query->expr->in(
83
                    $this->dbHandler->quoteColumn('owner_id', 'ezcontentobject'),
84
                    $subSelect
85
                );*/
86
87
            case Criterion\UserMetadata::OWNER:
88
                return $this->operateInt($query, 'content.owner_id', $criterion);
89
        }
90
91
        throw new RuntimeException("Invalid target criterion encountered:'" . $criterion->target . "'");
92
    }
93
}
94