Operators   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 15

Importance

Changes 0
Metric Value
wmc 22
lcom 1
cbo 15
dl 0
loc 118
rs 9.1666
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A doc() 0 4 1
A not() 0 4 1
A exists() 0 4 1
A type() 0 4 1
A in() 0 4 1
A regexp() 0 4 1
A equals() 0 4 1
A same() 0 4 1
A greaterThan() 0 4 1
A greaterThanOrEquals() 0 7 1
A lessThan() 0 4 1
A lessThanOrEquals() 0 7 1
A all() 0 4 1
A atLeastOne() 0 4 1
A exactly() 0 4 1
A none() 0 4 1
A one() 0 4 1
A listAll() 0 4 1
A listAtLeastOne() 0 4 1
A listExactly() 0 4 1
A listNone() 0 4 1
A listOne() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\yaysondb;
6
7
use hanneskod\yaysondb\Expression\ExpressionInterface;
8
9
/**
10
 * Collection of query operators
11
 */
12
class Operators
13
{
14
    public static function doc(array $query)
15
    {
16
        return new Expression\Doc($query);
17
    }
18
19
    public static function not(ExpressionInterface $expr)
20
    {
21
        return new Expression\Not($expr);
22
    }
23
24
    public static function exists()
25
    {
26
        return new Expression\Exists();
27
    }
28
29
    public static function type($type)
30
    {
31
        return new Expression\Type($type);
32
    }
33
34
    public static function in(array $list)
35
    {
36
        return new Expression\In($list);
37
    }
38
39
    public static function regexp($regexp)
40
    {
41
        return new Expression\Regexp($regexp);
42
    }
43
44
    public static function equals($operand)
45
    {
46
        return new Expression\Comparator\Equals($operand);
47
    }
48
49
    public static function same($operand)
50
    {
51
        return new Expression\Comparator\Same($operand);
52
    }
53
54
    public static function greaterThan($operand)
55
    {
56
        return new Expression\Comparator\GreaterThan($operand);
57
    }
58
59
    public static function greaterThanOrEquals($operand)
60
    {
61
        return self::atLeastOne(
62
            self::equals($operand),
63
            self::greaterThan($operand)
64
        );
65
    }
66
67
    public static function lessThan($operand)
68
    {
69
        return self::not(self::greaterThanOrEquals($operand));
70
    }
71
72
    public static function lessThanOrEquals($operand)
73
    {
74
        return self::atLeastOne(
75
            self::equals($operand),
76
            self::lessThan($operand)
77
        );
78
    }
79
80
    public static function all(ExpressionInterface ...$exprs)
81
    {
82
        return new Expression\Counter\All(...$exprs);
83
    }
84
85
    public static function atLeastOne(ExpressionInterface ...$exprs)
86
    {
87
        return new Expression\Counter\AtLeastOne(...$exprs);
88
    }
89
90
    public static function exactly($count, ExpressionInterface ...$exprs)
91
    {
92
        return new Expression\Counter\Exactly($count, ...$exprs);
93
    }
94
95
    public static function none(ExpressionInterface ...$exprs)
96
    {
97
        return self::not(self::atLeastOne(...$exprs));
98
    }
99
100
    public static function one(ExpressionInterface ...$exprs)
101
    {
102
        return self::exactly(1, ...$exprs);
103
    }
104
105
    public static function listAll(ExpressionInterface $expr)
106
    {
107
        return new Expression\Set\ListAll($expr);
108
    }
109
110
    public static function listAtLeastOne(ExpressionInterface $expr)
111
    {
112
        return new Expression\Set\ListAtLeastOne($expr);
113
    }
114
115
    public static function listExactly($count, ExpressionInterface $expr)
116
    {
117
        return new Expression\Set\ListExactly($count, $expr);
118
    }
119
120
    public static function listNone(ExpressionInterface $expr)
121
    {
122
        return self::not(self::listAtLeastOne($expr));
123
    }
124
125
    public static function listOne(ExpressionInterface $expr)
126
    {
127
        return self::listExactly(1, $expr);
128
    }
129
}
130