News   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 52
ccs 15
cts 15
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toXmlArray() 0 13 3
A propertiesToArray() 0 7 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
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 3
    public function __construct(array $items = [])
39
    {
40 3
        parent::__construct(compact('items'));
41 3
    }
42
43
    /**
44
     * @param array $data
45
     * @param array $aliases
46
     *
47
     * @return array
48
     */
49 1
    public function propertiesToArray(array $data, array $aliases = []): array
50
    {
51 1
        return ['articles' => array_map(function ($item) {
52 1
            if ($item instanceof NewsItem) {
53 1
                return $item->toJsonArray();
54
            }
55 1
        }, $this->get('items'))];
0 ignored issues
show
Bug introduced by
It seems like $this->get('items') can also be of type null; however, parameter $arr1 of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        }, /** @scrutinizer ignore-type */ $this->get('items'))];
Loading history...
56
    }
57
58 2
    public function toXmlArray()
59
    {
60 2
        $items = [];
61
62 2
        foreach ($this->get('items') as $item) {
63 2
            if ($item instanceof NewsItem) {
64 2
                $items[] = $item->toXmlArray();
65
            }
66
        }
67
68
        return [
69 2
            'ArticleCount' => count($items),
70 2
            'Articles' => $items,
71
        ];
72
    }
73
}
74