ButtonTemplate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 19.3 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 11
loc 57
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A create() 0 4 1
A toArray() 0 14 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
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template;
6
7
use Kerox\Messenger\Model\Message\Attachment\AbstractTemplate;
8
9
class ButtonTemplate extends AbstractTemplate
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $text;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Common\Button\AbstractButton[]
18
     */
19
    protected $buttons;
20
21
    /**
22
     * @var bool
23
     */
24
    protected $sharable;
25
26
    /**
27
     * Buttons constructor.
28
     *
29
     * @param \Kerox\Messenger\Model\Common\Button\AbstractButton[] $buttons
30
     */
31 1 View Code Duplication
    public function __construct(string $text, array $buttons, bool $sharable = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33 1
        parent::__construct();
34
35 1
        $this->isValidString($text, 640);
36 1
        $this->isValidArray($buttons, 3);
37
38 1
        $this->text = $text;
39 1
        $this->buttons = $buttons;
40 1
        $this->sharable = $sharable;
41 1
    }
42
43
    /**
44
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ButtonTemplate
45
     */
46 1
    public static function create(string $text, array $buttons, bool $sharable = false): self
47
    {
48 1
        return new self($text, $buttons, $sharable);
49
    }
50
51 1
    public function toArray(): array
52
    {
53 1
        $array = parent::toArray();
54
        $array += [
55
            'payload' => [
56 1
                'template_type' => AbstractTemplate::TYPE_BUTTON,
57 1
                'text' => $this->text,
58 1
                'buttons' => $this->buttons,
59 1
                'sharable' => $this->sharable,
60
            ],
61
        ];
62
63 1
        return $this->arrayFilter($array);
64
    }
65
}
66