Completed
Push — master ( 290f71...5c7d58 )
by Tobias
01:52
created

src/Model/LogoType/LogoType.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 ($data['status'] === 'INVALID_PARAMETER' && array_key_exists('message', $data['data'])) {
0 ignored issues
show
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 2
        $logoType = new self();
79 2
        $logoType->content = $data['content'] ?? null;
80 2
        $logoType->fileType = $data['file_type'] ?? null;
81
82 2
        return $logoType;
83
    }
84
85
    /**
86
     * @return array
87
     */
88 1
    public function toArray()
89
    {
90 1
        $data = [];
91 1
        if ($this->content !== null) {
92 1
            $data['content'] = $this->content;
93
        }
94 1
        if ($this->fileType !== null) {
95 1
            $data['file_type'] = $this->fileType;
96
        }
97
98 1
        return $data;
99
    }
100
}
101