At::at()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace DingRobot\Message\Traits;
4
5
trait At
6
{
7
    protected $mobiles = [];
8
    protected $all = false;
9
10
    /**
11
     * at 某人
12
     * at someone
13
     *
14
     * @param string|array $someone
15
     *
16
     * @return $this
17
     */
18 6
    public function at($someone = null)
19
    {
20 6
        if (is_string($someone) || is_numeric($someone)) {
21 6
            $this->mobiles[] = (string)$someone;
22 6
        } elseif (is_array($someone)) {
23 6
            $this->mobiles = array_merge($this->mobiles, $someone);
24
        }
25 6
        return $this;
26
    }
27
28
    /**
29
     * set at all active
30
     * at 全部人
31
     *
32
     * @return $this
33
     */
34 6
    public function atAll()
35
    {
36 6
        $this->all = true;
37 6
        return $this;
38
    }
39
40
    /**
41
     * cancel at all
42
     * 取消 at 全部人
43
     *
44
     * @return $this
45
     */
46 6
    public function notAtAll()
47
    {
48 6
        $this->all = false;
49 6
        return $this;
50
    }
51
52
53 8
    protected function getAt()
54
    {
55 8
        if (count($this->mobiles) || $this->all) {
56
            return [
57
                'at' => [
58 6
                    'atMobiles' => $this->mobiles,
59 6
                    'isAtAll'   => $this->all,
60
                ]
61
            ];
62
        } else {
63 2
            return [];
64
        }
65
    }
66
}