Completed
Push — master ( e36c6b...c46352 )
by Łukasz
14:01
created

IsUserEnabled   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 44
loc 44
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A accept() 4 4 1
A handle() 36 36 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Search\Legacy\Content\Common\Gateway\CriterionHandler;
12
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
13
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
14
use eZ\Publish\Core\Persistence\Database\SelectQuery;
15
16 View Code Duplication
class IsUserEnabled 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...
17
{
18
    public function accept(Criterion $criterion): bool
19
    {
20
        return $criterion instanceof Criterion\IsUserEnabled;
21
    }
22
23
    public function handle(
24
        CriteriaConverter $converter,
25
        SelectQuery $query,
26
        Criterion $criterion,
27
        array $languageSettings
28
    ) {
29
        $subSelect = $query->subSelect();
30
        $subSelect
31
            ->select(
32
                $this->dbHandler->quoteColumn('contentobject_id', 't1')
33
            )->from(
34
                $query->alias(
35
                    $this->dbHandler->quoteTable('ezuser'),
36
                    't1'
37
                )
38
            )->leftJoin(
39
                $query->alias(
40
                    $this->dbHandler->quoteTable('ezuser_setting'),
41
                    't2'
42
                ),
43
                $query->expr->eq(
44
                    $this->dbHandler->quoteColumn('contentobject_id', 't1'),
45
                    $this->dbHandler->quoteColumn('user_id', 't2')
46
                )
47
            )->where(
48
                $query->expr->eq(
49
                    $this->dbHandler->quoteColumn('is_enabled', 't2'),
50
                    (int) reset($criterion->value)
51
                )
52
            );
53
54
        return $query->expr->in(
55
            $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
56
            $subSelect
57
        );
58
    }
59
}
60