GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Element   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 17.54 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getButtons() 0 4 1
A getDefaultAction() 0 4 1
A jsonSerialize() 10 10 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
namespace Tgallice\FBMessenger\Model\Attachment\Template\Generic;
4
5
use Tgallice\FBMessenger\Model\Button;
6
use Tgallice\FBMessenger\Model\Attachment\Template\AbstractElement;
7
use Tgallice\FBMessenger\Model\DefaultAction;
8
9
class Element extends AbstractElement
10
{
11
    /**
12
     * @var null|DefaultAction
13
     */
14
    private $defaultAction;
15
16
    /**
17
     * @var null|Button[]
18
     */
19
    private $buttons;
20
21
    /**
22
     * @param string $title
23
     */
24 9
    public function __construct($title, $subtitle = null, $imageUrl = null, array $buttons = null, DefaultAction $defaultAction = null)
25
    {
26 9
        parent::__construct($title, $subtitle, $imageUrl);
27
28 7
        if (count($buttons) > 3) {
29 1
            throw new \InvalidArgumentException('A generic element can not have more than 3 buttons.');
30
        }
31
32 6
        $this->buttons = $buttons;
33 6
        $this->defaultAction = $defaultAction;
34 6
    }
35
36
    /**
37
     * @return null|Button[]
38
     */
39 1
    public function getButtons()
40
    {
41 1
        return $this->buttons;
42
    }
43
44
    /**
45
     * @return null|DefaultAction
46
     */
47 1
    public function getDefaultAction()
48
    {
49 1
        return $this->defaultAction;
50
    }
51
52
    /**
53
     * @return array
54
     */
55 1 View Code Duplication
    public function jsonSerialize()
56
    {
57
        return [
58 1
            'title' => $this->getTitle(),
59 1
            'image_url' => $this->getImageUrl(),
60 1
            'subtitle' => $this->getSubtitle(),
61 1
            'buttons' => $this->buttons,
62 1
            'default_action' => $this->defaultAction,
63 1
        ];
64
    }
65
}
66