Select::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace mav3rick177\RapidPagination\Base\Query;
4
5
/**
6
 * Class Select
7
 */
8
class Select extends SelectOrUnionAll
9
{
10
    /**
11
     * @var ConditionGroup[]
12
     */
13
    protected $where;
14
15
    /**
16
     * @var Order[]
17
     */
18
    protected $orders;
19
20
    /**
21
     * @var Limit
22
     */
23
    protected $limit;
24
25
    /**
26
     * Select constructor.
27
     *
28
     * @param ConditionGroup[] $where
29
     * @param Order[]          $orders
30
     * @param Limit            $limit
31
     */
32 17
    public function __construct(array $where, array $orders, Limit $limit)
33
    {
34 17
        $this->where = $where;
35 17
        $this->orders = static::validate(...$orders);
0 ignored issues
show
Documentation Bug introduced by
It seems like static::validate(...$orders) of type array<integer,array<inte...ion\Base\Query\Order>>> is incompatible with the declared type array<integer,object<mav...tion\Base\Query\Order>> of property $orders.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36 17
        $this->limit = $limit;
37
    }
38
39
    /**
40
     * @param  Order[] ...$orders
41
     * @return Order[]
42
     */
43 17
    protected static function validate(Order ...$orders)
44
    {
45 17
        return $orders;
46
    }
47
48
    /**
49
     * @return ConditionGroup[]
50
     */
51 17
    public function where()
52
    {
53 17
        return $this->where;
54
    }
55
56
    /**
57
     * @return Order[]
58
     */
59 17
    public function orders()
60
    {
61 17
        return $this->orders;
62
    }
63
64
    /**
65
     * @return Limit
66
     */
67 17
    public function limit()
68
    {
69 17
        return $this->limit;
70
    }
71
72
    /**
73
     * @return static
74
     */
75 10
    public function inverse()
76
    {
77 10
        return new static(
78 10
            array_map(static function (ConditionGroup $group) {
79 10
                return $group->inverse();
80 10
            }, $this->where),
81 10
            array_map(static function (Order $order) {
82 10
                return $order->inverse();
83 10
            }, $this->orders),
84 10
            $this->limit->inverse()
85
        );
86
    }
87
88
    /**
89
     * Clone Select.
90
     */
91 View Code Duplication
    public function __clone()
0 ignored issues
show
Duplication introduced by
This method 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...
92
    {
93
        $this->where = array_map(static function (ConditionGroup $group) {
94
            return clone $group;
95
        }, $this->where);
96
        $this->orders = array_map(static function (Order $order) {
97
            return clone $order;
98
        }, $this->orders);
99
        $this->limit = clone $this->limit;
100
    }
101
102
    /**
103
     * Retrieve an external iterator.
104
     *
105
     * @return \ArrayIterator|Select[]
106
     */
107
    public function getIterator()
108
    {
109
        return new \ArrayIterator([$this]);
110
    }
111
}
112