Passed
Push — main ( a33de3...4370d9 )
by Artem
02:12
created

ContentBody::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace CloudPlayDev\ConfluenceClient\Entity;
5
6
7
use Webmozart\Assert\Assert;
8
use function in_array;
9
10
class ContentBody implements Hydratable
11
{
12
    /**
13
     * confluence representation (markup html)
14
     */
15
    public const REPRESENTATION_STORAGE = 'storage';
16
17
    /**
18
     * confluence representation (markup)
19
     */
20
    public const REPRESENTATION_EDITOR = 'editor';
21
22
    /**
23
     * confluence representation  (xhtml)
24
     */
25
    public const REPRESENTATION_VIEW = 'view';
26
27
    /**
28
     * confluence representation
29
     */
30
    public const REPRESENTATION_EXPORT_VIEW = 'export_view';
31
32
    /**
33
     * confluence representation
34
     */
35
    public const REPRESENTATION_STYLED_VIEW = 'styled_view';
36
37
    /**
38
     * @example <ac:link><ri:user ri:userkey="a-valid-account-id" /></ac:link>
39
     * @var string
40
     */
41
    private string $value = '';
42
    private string $representation = self::REPRESENTATION_STORAGE;
43
44
    public static function load(array $data): Hydratable
45
    {
46
        $contentBody = new self;
47
        Assert::keyExists($data, 'value');
48
        Assert::keyExists($data, 'representation');
49
        Assert::string($data['value']);
50
        Assert::string($data['representation']);
51
52
        $contentBody->setValue($data['value']);
53
        $contentBody->setRepresentation($data['representation']);
54
55
        return $contentBody;
56
57
    }
58
59
    public static function isSupported(string $representation): bool
60
    {
61
        return (in_array($representation, [
62
            self::REPRESENTATION_STORAGE,
63
            self::REPRESENTATION_EDITOR,
64
            self::REPRESENTATION_VIEW,
65
            self::REPRESENTATION_EXPORT_VIEW,
66
            self::REPRESENTATION_STYLED_VIEW,
67
        ], true));
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getValue(): string
74
    {
75
        return $this->value;
76
    }
77
78
    /**
79
     * @param string $value
80
     * @return self
81
     */
82
    public function setValue(string $value): self
83
    {
84
        $this->value = $value;
85
        return $this;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getRepresentation(): string
92
    {
93
        return $this->representation;
94
    }
95
96
    /**
97
     * @param string $representation
98
     * @return self
99
     */
100
    public function setRepresentation(string $representation): self
101
    {
102
        $this->representation = $representation;
103
        return $this;
104
    }
105
106
107
}
108