Completed
Push — ezp-30882-thumbnail-strategy-i... ( b3e424...83a23b )
by
unknown
13:58
created

UserEmail::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 48

Duplication

Lines 48
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 4
dl 48
loc 48
rs 9.1344
c 0
b 0
f 0
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\Search\Legacy\Content\Common\Gateway\CriterionHandler;
10
11
use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
12
use eZ\Publish\Core\Persistence\TransformationProcessor;
13
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
14
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
15
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
16
use eZ\Publish\Core\Persistence\Database\SelectQuery;
17
18 View Code Duplication
class UserEmail extends CriterionHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
19
{
20
    /** @var \eZ\Publish\Core\Persistence\TransformationProcessor */
21
    private $transformationProcessor;
22
23
    public function __construct(DatabaseHandler $dbHandler, TransformationProcessor $transformationProcessor)
24
    {
25
        parent::__construct($dbHandler);
26
27
        $this->transformationProcessor = $transformationProcessor;
28
    }
29
30
    public function accept(Criterion $criterion): bool
31
    {
32
        return $criterion instanceof Criterion\UserEmail;
33
    }
34
35
    public function handle(
36
        CriteriaConverter $converter,
37
        SelectQuery $query,
38
        Criterion $criterion,
39
        array $languageSettings
40
    ) {
41
        if (Criterion\Operator::LIKE === $criterion->operator) {
42
            $expression = $query->expr->like(
43
                $this->dbHandler->quoteColumn('email', 't1'),
44
                $query->bindValue(
45
                    str_replace(
46
                        '*',
47
                        '%',
48
                        addcslashes(
49
                            $this->transformationProcessor->transformByGroup(
50
                                $criterion->value,
51
                                'lowercase'
52
                            ),
53
                            '%_'
54
                        )
55
                    )
56
                )
57
            );
58
        } else {
59
            $expression = $query->expr->in(
60
                $this->dbHandler->quoteColumn('email', 't1'),
61
                $criterion->value
62
            );
63
        }
64
65
        $subSelect = $query->subSelect();
66
        $subSelect
67
            ->select(
68
                $this->dbHandler->quoteColumn('contentobject_id', 't1')
69
            )->from(
70
                $query->alias(
71
                    $this->dbHandler->quoteTable('ezuser'),
72
                    't1'
73
                )
74
            )->where(
75
                $expression
76
            );
77
78
        return $query->expr->in(
79
            $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
80
            $subSelect
81
        );
82
    }
83
}
84