expr::any()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 10
1
<?php
2
3
namespace mindplay\sql\model;
4
5
use UnexpectedValueException;
6
7
/**
8
 * Pseudo-namespace for expression builder functions
9
 */
10
abstract class expr
11
{
12
    /**
13
     * Combine a list of expressions with OR operators
14
     * 
15
     * @param string[] $exprs
16
     */
17 1
    public static function any(array $exprs): string
18
    {
19 1
        if (count($exprs) === 0) {
20 1
            throw new UnexpectedValueException("unexpected empty array");
21
        }
22
23 1
        return count($exprs) > 1
24 1
            ? "(" . implode(") OR (", $exprs) . ")"
25 1
            : $exprs[0];
26
    }
27
    
28
    /**
29
     * Combine a list of expressions with AND operators
30
     * 
31
     * @param string[] $exprs
32
     */
33 1
    public static function all(array $exprs): string
34
    {
35 1
        if (count($exprs) === 0) {
36 1
            throw new UnexpectedValueException("unexpected empty array");
37
        }
38
        
39 1
        return count($exprs) > 1
40 1
            ? "(" . implode(") AND (", $exprs) . ")"
41 1
            : $exprs[0];
42
    }
43
}
44