ComparatorVisitor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 8
dl 0
loc 61
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A visitComparator() 0 4 1
A visitReverseComparator() 0 9 2
A visitCallbackComparator() 0 4 1
A visitMultiComparator() 0 5 1
A visitSelectorComparator() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB\Query;
12
13
use Cubiche\Core\Comparable\CallbackComparator;
14
use Cubiche\Core\Comparable\Comparator;
15
use Cubiche\Core\Comparable\MultiComparator;
16
use Cubiche\Core\Comparable\ReverseComparator;
17
use Cubiche\Core\Comparable\SelectorComparator;
18
use Cubiche\Core\Visitor\Visitor;
19
20
/**
21
 * Comparator Visitor Class.
22
 *
23
 * @author Karel Osorio Ramírez <[email protected]>
24
 */
25
class ComparatorVisitor extends Visitor
26
{
27
    use VisitorTrait;
28
29
    /**
30
     * @param QueryBuilder $queryBuilder
31
     */
32
    public function __construct(QueryBuilder $queryBuilder)
33
    {
34
        parent::__construct();
35
36
        $this->queryBuilder = $queryBuilder;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function visitComparator(Comparator $comparator)
43
    {
44
        throw $this->notSupportedException($comparator);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function visitReverseComparator(ReverseComparator $comparator)
51
    {
52
        $reverse = $comparator->comparator()->reverse();
0 ignored issues
show
Bug introduced by
The method comparator() does not exist on Cubiche\Core\Comparable\ReverseComparator. Did you maybe mean defaultComparator()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
53
        if ($reverse instanceof ReverseComparator) {
54
            throw $this->notSupportedException($comparator);
55
        }
56
57
        return $reverse->accept($this);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function visitCallbackComparator(CallbackComparator $comparator)
64
    {
65
        $this->notSupportedException($comparator);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function visitMultiComparator(MultiComparator $comparator)
72
    {
73
        $comparator->firstComparator()->accept($this);
74
        $comparator->secondComparator()->accept($this);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function visitSelectorComparator(SelectorComparator $comparator)
81
    {
82
        $field = $this->createField($comparator->selector());
0 ignored issues
show
Documentation introduced by
$comparator->selector() is of type callable, but the function expects a object<Cubiche\Core\Selector\SelectorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
        $this->queryBuilder->sort($field->name(), $comparator->direction()->value());
84
    }
85
}
86