Content::getError()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
use Acquia\LiftClient\Exception\LiftSdkException;
6
7
class Content extends Entity
8
{
9
    /**
10
     * @param array $array
11
     */
12 57
    public function __construct(array $array = [])
13
    {
14
        // Set content_hub as default content_connector_id when adding content
15 57
        $array['content_connector_id'] = 'content_hub';
16 57
        parent::__construct($array);
17 57
    }
18
19
    /**
20
     * @param string $id
21
     *
22
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
23
     *
24
     * @return \Acquia\LiftClient\Entity\Content
25
     */
26 36
    public function setId($id)
27
    {
28 36
        if (!is_string($id)) {
29 3
            throw new LiftSdkException('Argument must be an instance of string.');
30
        }
31 33
        $this['id'] = $id;
32
33 33
        return $this;
34
    }
35
36
    /**
37
     * Gets the 'id' parameter.
38
     *
39
     * @return string
40
     */
41 15
    public function getId()
42
    {
43 15
        return $this->getEntityValue('id', '');
44
    }
45
46
    /**
47
     * @param string $contentConnectorId
48
     *
49
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
50
     *
51
     * @return \Acquia\LiftClient\Entity\Content
52
     */
53 33 View Code Duplication
    public function setContentConnectorId($contentConnectorId = 'content_hub')
54
    {
55 33
        if (!is_string($contentConnectorId)) {
56 3
            throw new LiftSdkException('Argument must be an instance of string.');
57
        }
58 30
        $this['content_connector_id'] = $contentConnectorId;
59
60 30
        return $this;
61
    }
62
63
    /**
64
     * Gets the 'content_connector_id' parameter.
65
     *
66
     * @return string
67
     */
68 18
    public function getContentConnectorId()
69
    {
70 18
        return $this->getEntityValue('content_connector_id', 'content_hub');
71
    }
72
73
    /**
74
     * @param string $baseUrl
75
     *
76
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
77
     *
78
     * @return \Acquia\LiftClient\Entity\Content
79
     */
80 33
    public function setBaseUrl($baseUrl)
81
    {
82 33
        if (!is_string($baseUrl)) {
83 3
            throw new LiftSdkException('Argument must be an instance of string.');
84
        }
85 30
        $this['base_url'] = $baseUrl;
86
87 30
        return $this;
88
    }
89
90
    /**
91
     * Gets the 'base_url' parameter.
92
     *
93
     * @return string
94
     */
95 12
    public function getBaseUrl()
96
    {
97 12
        return $this->getEntityValue('base_url', '');
98
    }
99
100
    /**
101
     * @param ViewMode $viewMode
102
     *
103
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
104
     *
105
     * @return \Acquia\LiftClient\Entity\Content
106
     */
107 33
    public function setViewMode(ViewMode $viewMode)
108
    {
109 33
        $this['view_mode'] = $viewMode->getArrayCopy();
110
111 33
        return $this;
112
    }
113
114
    /**
115
     * Gets the 'id' parameter.
116
     *
117
     * @return viewMode
118
     */
119 15
    public function getViewMode()
120
    {
121 15
        $viewMode = $this->getEntityValue('view_mode', []);
122
123 15
        return new ViewMode($viewMode);
124
    }
125
126
    /**
127
     * Gets the 'errors' parameter.
128
     *
129
     * @return Error|null The errors, if there were any
130
     */
131 3
    public function getError()
132
    {
133 3
        $error = $this->getEntityValue('error', null);
134 3
        if ($error == null) {
135
            return null;
136
        }
137
138 3
        return new Error($error);
139
    }
140
}
141