LogoType   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 3.26 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80.77%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 3
loc 92
ccs 21
cts 26
cp 0.8077
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getContent() 0 4 1
A withContent() 0 7 1
A getFileType() 0 4 1
A withFileType() 0 7 1
A createFromArray() 3 12 3
A toArray() 0 12 3

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 Billogram\Model\LogoType;
6
7
use Billogram\Exception\Domain\ValidationException;
8
use Billogram\Model\CreatableFromArray;
9
10
class LogoType implements CreatableFromArray
11
{
12
    /**
13
     * @var string
14
     */
15
    private $content;
16
17
    /**
18
     * @var string
19
     */
20
    private $fileType;
21
22
    /**
23
     * @return string
24
     */
25
    public function getContent(): string
26
    {
27
        return $this->content;
28
    }
29
30
    /**
31
     * @param string $content
32
     *
33
     * @return LogoType
34
     */
35 1
    public function withContent(string $content)
36
    {
37 1
        $new = clone $this;
38 1
        $new->content = $content;
39
40 1
        return $new;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getFileType(): string
47
    {
48
        return $this->fileType;
49
    }
50
51
    /**
52
     * @param string $fileType
53
     *
54
     * @return LogoType
55
     */
56 1
    public function withFileType(string $fileType)
57
    {
58 1
        $new = clone $this;
59 1
        $new->fileType = $fileType;
60
61 1
        return $new;
62
    }
63
64
    /**
65
     * Create an API response object from the HTTP response from the API server.
66
     *
67
     * @param array $data
68
     *
69
     * @return self
70
     *
71
     * @throws ValidationException
72
     */
73 2
    public static function createFromArray(array $data)
74
    {
75 2 View Code Duplication
        if ('INVALID_PARAMETER' === $data['status'] && array_key_exists('message', $data['data'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
76
            throw new ValidationException($data['data']['message']);
77
        }
78
79 2
        $logoType = new self();
80 2
        $logoType->content = $data['content'] ?? null;
81 2
        $logoType->fileType = $data['file_type'] ?? null;
82
83 2
        return $logoType;
84
    }
85
86
    /**
87
     * @return array
88
     */
89 1
    public function toArray()
90
    {
91 1
        $data = [];
92 1
        if (null !== $this->content) {
93 1
            $data['content'] = $this->content;
94
        }
95 1
        if (null !== $this->fileType) {
96 1
            $data['file_type'] = $this->fileType;
97
        }
98
99 1
        return $data;
100
    }
101
}
102