Completed
Pull Request — master (#1606)
by
unknown
03:24
created

News::propertiesToArray()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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