Passed
Push — master ( a2a2c3...5dc036 )
by Carlos
03:01
created

News   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toXmlArray() 0 15 3
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\Messages;
13
14
/**
15
 * Class News.
16
 *
17
 * @author overtrue <[email protected]>
18
 */
19
class News extends Message
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $type = 'news';
25
26
    /**
27
     * @var array
28
     */
29
    protected $properties = [
30
        'items',
31
    ];
32
33
    /**
34
     * News constructor.
35
     *
36
     * @param array $items
37
     */
38
    public function __construct(array $items = [])
39
    {
40
        parent::__construct(compact('items'));
41
    }
42
43
    public function toXmlArray()
44
    {
45
        $items = [];
46
47
        foreach ($this->get('items') as $article) {
48
            if ($article instanceof NewsItem) {
49
                $items[] = $article->toXmlArray();
50
            }
51
        }
52
53
        return [
54
            'ArticleCount' => count($items),
55
            'Articles' => $items,
56
        ];
57
    }
58
}
59