Postback   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 49
loc 49
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A create() 4 4 1
A toArray() 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
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Common\Button;
6
7 View Code Duplication
class Postback extends AbstractButton
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $title;
13
14
    /**
15
     * @var string
16
     */
17
    protected $payload;
18
19
    /**
20
     * Postback constructor.
21
     *
22
     * @throws \Kerox\Messenger\Exception\MessengerException
23
     */
24 10
    public function __construct(string $title, string $payload)
25
    {
26 10
        parent::__construct(self::TYPE_POSTBACK);
27
28 10
        $this->isValidString($title, 20);
29 10
        $this->isValidString($payload, 1000);
30
31 10
        $this->title = $title;
32 10
        $this->payload = $payload;
33 10
    }
34
35
    /**
36
     * @throws \Kerox\Messenger\Exception\MessengerException
37
     *
38
     * @return \Kerox\Messenger\Model\Common\Button\Postback
39
     */
40 10
    public static function create(string $title, string $payload): self
41
    {
42 10
        return new self($title, $payload);
43
    }
44
45 7
    public function toArray(): array
46
    {
47 7
        $array = parent::toArray();
48
        $array += [
49 7
            'title' => $this->title,
50 7
            'payload' => $this->payload,
51
        ];
52
53 7
        return $array;
54
    }
55
}
56