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

News::toXmlArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 15
ccs 0
cts 13
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
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