MessageApi::__call()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
rs 8.439
cc 5
eloc 18
nc 5
nop 2
1
<?php
2
namespace Wechat\API;
3
4
/**
5
 * 微信被动回复.
6
 *
7
 * @author Tian.
8
 */
9
class MessageApi extends BaseApi
10
{
11
    /**
12
     * [__call 魔术方法 生成回调array]
13
     *
14
     * @param  mixed $MsgType [类型]
15
     * @param  array $datas   [参数]
16
     *
17
     * @return string xml          [XML]
18
     */
19
    public function __call($MsgType, $datas)
20
    {
21
        $MsgType = strtolower($MsgType);
22
23
        $data               = [];
24
        $data['CreateTime'] = time();
25
        $data['MsgType']    = $MsgType;
26
27
        $datas = reset($datas);
28
29
        if ($MsgType == 'text') {
30
            $data['Content'] = $datas['Content'];
31
        } elseif ($MsgType == 'news') {
32
            $data['ArticleCount'] = count($datas['item']);
33
            $data['Articles']     = $datas;
34
        } elseif ($MsgType == 'music') {
35
            $data['Music'] = $datas;
36
        } elseif ($MsgType == 'video') {
37
            $data['Video'] = $datas;
38
        } else {
39
            $data[$MsgType] = $datas;
40
        }
41
42
        return $data;
43
    }
44
}
45