Completed
Pull Request — master (#716)
by mingyoung
03:27
created

MediaPress   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
rs 10
ccs 8
cts 9
cp 0.8889
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A select() 0 9 1
A mediaPress() 0 8 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
 * MediaPress.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @copyright 2017
22
 *
23
 * @see      https://github.com/overtrue
24
 * @see      http://overtrue.me
25
 */
26
27
namespace EasyWeChat\MediaPress;
28
29
use EasyWeChat\Core\AbstractAPI;
30
use EasyWeChat\Core\Exceptions\InvalidArgumentException;
31
32
class MediaPress extends AbstractAPI
33
{
34
    use ManageComments, ManageCommentReplies;
35
36
    const API_OPEN_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/open';
37
    const API_CLOSE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/close';
38
    const API_LIST_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/list';
39
    const API_MARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/markelect';
40
    const API_UNMARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/unmarkelect';
41
    const API_DELETE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/delete';
42
    const API_REPLY_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/reply/add';
43
    const API_DELETE_REPLY = 'https://api.weixin.qq.com/cgi-bin/comment/reply/delete';
44
45
    /**
46
     * @var array
47
     */
48
    protected $mediaPress;
49
50
    /**
51
     * Select an article.
52
     *
53
     * @param int $dataId
54
     * @param int $index
55
     *
56
     * @return $this
57
     */
58 8
    public function select($dataId, $index = null)
59
    {
60 8
        $this->mediaPress = [
61 8
            'msg_data_id' => $dataId,
62 8
            'index' => $index,
63
        ];
64
65 8
        return $this;
66
    }
67
68
    /**
69
     * Return the media-press.
70
     *
71
     * @return array
72
     *
73
     * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException
74
     */
75 8
    protected function mediaPress()
0 ignored issues
show
Best Practice introduced by
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
76
    {
77 8
        if ($this->mediaPress) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->mediaPress of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
78 8
            return $this->mediaPress;
79
        }
80
81
        throw new InvalidArgumentException('Missing media-press data.');
82
    }
83
}
84