Passed
Push — master ( 5dc036...8f7930 )
by Carlos
03:16
created

NewsItem   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 43.9 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 18
loc 41
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toJsonArray() 9 9 1
A toXmlArray() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 NewsItem.
16
 */
17
class NewsItem extends Message
18
{
19
    /**
20
     * Messages type.
21
     *
22
     * @var string
23
     */
24
    protected $type = 'news';
25
26
    /**
27
     * Properties.
28
     *
29
     * @var array
30
     */
31
    protected $properties = [
32
        'title',
33
        'description',
34
        'url',
35
        'image',
36
    ];
37
38 View Code Duplication
    public function toJsonArray()
39
    {
40
        return [
41
            'title' => $this->get('title'),
42
            'description' => $this->get('description'),
43
            'url' => $this->get('url'),
44
            'picurl' => $this->get('image'),
45
        ];
46
    }
47
48 View Code Duplication
    public function toXmlArray()
49
    {
50
        return [
51
            'Title' => $this->get('title'),
52
            'Description' => $this->get('description'),
53
            'Url' => $this->get('url'),
54
            'PicUrl' => $this->get('image'),
55
        ];
56
    }
57
}
58