Passed
Push — master ( 85e933...e19d09 )
by Carlos
01:46 queued 15s
created

News   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 35
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A propertiesToArray() 0 7 2
A __construct() 0 3 1
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\Work\GroupRobot\Messages;
13
14
/**
15
 * Class News.
16
 *
17
 * @author her-cat <[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 = ['items'];
30
31
    /**
32
     * News constructor.
33
     *
34
     * @param array $items
35
     */
36 2
    public function __construct(array $items = [])
37
    {
38 2
        parent::__construct(compact('items'));
39 2
    }
40
41
    /**
42
     * @param array $data
43
     * @param array $aliases
44
     *
45
     * @return array
46
     */
47
    public function propertiesToArray(array $data, array $aliases = []): array
48
    {
49 2
        return ['articles' => array_map(function ($item) {
50 2
            if ($item instanceof NewsItem) {
51 2
                return $item->toJsonArray();
52
            }
53 2
        }, $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

53
        }, /** @scrutinizer ignore-type */ $this->get('items'))];
Loading history...
54
    }
55
}
56