Passed
Push — master ( a57761...826c30 )
by test
04:09
created

Clause::interceptWhereClause()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 5
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 4
rs 10
1
<?php
2
3
namespace EasyIM\Kernel\Clauses;
4
5
/**
6
 * Class Clause.
7
 */
8
class Clause
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $clauses = [
14
        'where' => [],
15
    ];
16
17
    /**
18
     * @param mixed ...$args
19
     *
20
     * @return $this
21
     */
22 2
    public function where(...$args)
23
    {
24 2
        array_push($this->clauses['where'], $args);
25
26 2
        return $this;
27
    }
28
29
    /**
30
     * @param mixed $payload
31
     *
32
     * @return bool
33
     */
34 8
    public function intercepted($payload)
35
    {
36 8
        return (bool) $this->interceptWhereClause($payload);
37
    }
38
39
    /**
40
     * @param mixed $payload
41
     *
42
     * @return bool
43
     */
44 8
    protected function interceptWhereClause($payload)
45
    {
46 8
        foreach ($this->clauses['where'] as $item) {
47 2
            list($key, $value) = $item;
48 2
            if (isset($payload[$key]) && $payload[$key] !== $value) {
49 2
                return true;
50
            }
51
        }
52
53 8
        return false;
54
    }
55
}
56