Completed
Push — master ( 3bbe72...a1f8d5 )
by Carlos
05:23 queued 02:38
created

AbstractMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 5
c 3
b 0
f 2
lcom 0
cbo 1
dl 0
loc 82
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
A __get() 0 8 2
A __set() 0 10 2
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
/**
13
 * AbstractMessage.php.
14
 *
15
 * @author    overtrue <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\Message;
22
23
use EasyWeChat\Support\Attribute;
24
25
/**
26
 * Class AbstractMessage.
27
 */
28
abstract class AbstractMessage extends Attribute
29
{
30
    /**
31
     * Message type.
32
     *
33
     * @var string
34
     */
35
    protected $type;
36
37
    /**
38
     * Message id.
39
     *
40
     * @var int
41
     */
42
    protected $id;
43
44
    /**
45
     * Message target user open id.
46
     *
47
     * @var string
48
     */
49
    protected $to;
50
51
    /**
52
     * Message sender open id.
53
     *
54
     * @var string
55
     */
56
    protected $from;
57
58
    /**
59
     * Message attributes.
60
     *
61
     * @var array
62
     */
63
    protected $properties = [];
64
65
    /**
66
     * Return type name message.
67
     *
68
     * @return string
69
     */
70 4
    public function getType()
71
    {
72 4
        return $this->type;
73
    }
74
75
    /**
76
     * Magic getter.
77
     *
78
     * @param string $property
79
     *
80
     * @return mixed
81
     */
82 7
    public function __get($property)
83
    {
84 7
        if (property_exists($this, $property)) {
85 2
            return $this->$property;
86
        }
87
88 7
        return parent::__get($property);
89
    }
90
91
    /**
92
     * Magic setter.
93
     *
94
     * @param string $property
95
     * @param mixed  $value
96
     *
97
     * @return AbstractMessage
98
     */
99 5
    public function __set($property, $value)
100
    {
101 5
        if (property_exists($this, $property)) {
102 1
            $this->$property = $value;
103 1
        } else {
104 5
            parent::__set($property, $value);
105
        }
106
107 5
        return $this;
108
    }
109
}
110