Passed
Push — master ( c55c4a...28db53 )
by y
01:27
created

Predicate::compareArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
namespace Helix\DB\SQL;
4
5
use Helix\DB\Select;
6
7
/**
8
 * Represents a logical expression. Produces more predicates.
9
 */
10
class Predicate extends Expression implements ValueInterface {
11
12
    use PredicateTrait;
13
14
    /**
15
     * `(... AND ...)`
16
     *
17
     * @param string[] $conditions
18
     * @return Predicate
19
     */
20
    public static function all (array $conditions) {
21
        if (count($conditions) === 1) {
22
            return reset($conditions);
23
        }
24
        return new static('(' . implode(' AND ', $conditions) . ')');
25
    }
26
27
    /**
28
     * `(... OR ...)`
29
     *
30
     * @param string[] $conditions
31
     * @return Predicate
32
     */
33
    public static function any (array $conditions) {
34
        if (count($conditions) === 1) {
35
            return reset($conditions);
36
        }
37
        return new static('(' . implode(' OR ', $conditions) . ')');
38
    }
39
40
    /**
41
     * `NOT($this)`
42
     *
43
     * @return Predicate
44
     */
45
    public function invert () {
46
        return new static("NOT({$this})");
47
    }
48
}