Completed
Pull Request — master (#1315)
by mingyoung
03:18
created

Clause::where()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\Kernel\Clauses;
13
14
/**
15
 * Class Clause.
16
 *
17
 * @author mingyoung <[email protected]>
18
 */
19
class Clause
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $clauses = [
25
        'where' => [],
26
    ];
27
28
    /**
29
     * @param string $key
30
     * @param string $value
31
     *
32
     * @return $this
33
     */
34
    public function where(...$args)
35
    {
36
        array_push($this->clauses['where'], $args);
37
38
        return $this;
39
    }
40
41
    /**
42
     * @param mixed $payload
43
     *
44
     * @return bool
45
     */
46
    public function intercepted($payload)
47
    {
48
        return (bool) $this->interceptWhereClause($payload);
49
    }
50
51
    /**
52
     * @param mixed $payload
53
     *
54
     * @return bool
55
     */
56
    protected function interceptWhereClause($payload)
57
    {
58
        foreach ($this->clauses['where'] as [$key, $value]) {
59
            if (isset($payload[$key]) && $payload[$key] !== $value) {
60
                return true;
61
            }
62
        }
63
    }
64
}
65