1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the tmilos/scim-schema package. |
||
5 | * |
||
6 | * (c) Milos Tomic <[email protected]> |
||
7 | * |
||
8 | * This source file is subject to the MIT license that is bundled |
||
9 | * with this source code in the file LICENSE. |
||
10 | */ |
||
11 | |||
12 | namespace Tmilos\ScimSchema\Model\v2; |
||
13 | |||
14 | use Tmilos\ScimSchema\Model\Resource; |
||
15 | use Tmilos\ScimSchema\ScimConstants; |
||
16 | use Tmilos\ScimSchema\ScimConstantsV2; |
||
17 | |||
18 | class ResourceType extends Resource |
||
19 | { |
||
20 | /** @var string */ |
||
21 | protected $name; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $description; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $endpoint; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $schema; |
||
31 | |||
32 | /** |
||
33 | * schema => required. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $schemaExtensions; |
||
38 | |||
39 | public function getResourceType() |
||
40 | { |
||
41 | return ScimConstants::RESOURCE_TYPE_RESOURCE_TYPE; |
||
42 | } |
||
43 | |||
44 | public function getSchemaId() |
||
45 | { |
||
46 | return ScimConstantsV2::SCHEMA_RESOURCE_TYPE; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getName() |
||
53 | { |
||
54 | return $this->name; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $name |
||
59 | */ |
||
60 | public function setName($name) |
||
61 | { |
||
62 | $this->name = $name; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getDescription() |
||
69 | { |
||
70 | return $this->description; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $description |
||
75 | */ |
||
76 | public function setDescription($description) |
||
77 | { |
||
78 | $this->description = $description; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getEndpoint() |
||
85 | { |
||
86 | return $this->endpoint; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param string $endpoint |
||
91 | */ |
||
92 | public function setEndpoint($endpoint) |
||
93 | { |
||
94 | $this->endpoint = $endpoint; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getSchema() |
||
101 | { |
||
102 | return $this->schema; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param string $schema |
||
107 | */ |
||
108 | public function setSchema($schema) |
||
109 | { |
||
110 | $this->schema = $schema; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * schema => required. |
||
115 | * |
||
116 | * @return string[] |
||
117 | */ |
||
118 | public function getSchemaExtensions() |
||
119 | { |
||
120 | return $this->schemaExtensions; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @param string $schema |
||
125 | * @param bool $required |
||
126 | */ |
||
127 | public function addSchemaExtension($schema, $required) |
||
128 | { |
||
129 | $this->schemaExtensions[(string) $schema] = (bool) $required; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param string $schema |
||
134 | */ |
||
135 | public function removeSchemaExtension($schema) |
||
136 | { |
||
137 | unset($this->schemaExtensions[(string) $schema]); |
||
138 | } |
||
139 | |||
140 | public function serializeObject() |
||
141 | { |
||
142 | $result = parent::serializeObject(); |
||
143 | |||
144 | $result['name'] = $this->name; |
||
145 | $result['description'] = $this->description; |
||
146 | $result['endpoint'] = $this->endpoint; |
||
147 | $result['schema'] = $this->schema; |
||
148 | if ($this->schemaExtensions) { |
||
0 ignored issues
–
show
|
|||
149 | $result['schemaExtensions'] = []; |
||
150 | foreach ($this->schemaExtensions as $schema => $required) { |
||
151 | $result['schemaExtensions'][] = [ |
||
152 | 'schema' => $schema, |
||
153 | 'required' => (bool) $required, |
||
154 | ]; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | return $result; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @param array $data |
||
163 | * |
||
164 | * @return ResourceType |
||
165 | */ |
||
166 | public static function deserializeObject(array $data) |
||
167 | { |
||
168 | /** @var ResourceType $result */ |
||
169 | $result = self::deserializeCommonAttributes($data); |
||
170 | $result->name = $data['name']; |
||
171 | $result->description = $data['description']; |
||
172 | $result->endpoint = $data['endpoint']; |
||
173 | $result->schema = $data['schema']; |
||
174 | if (isset($data['schemaExtensions'])) { |
||
175 | $result->schemaExtensions = []; |
||
176 | foreach ($data['schemaExtensions'] as $schemaExtension) { |
||
177 | $result->schemaExtensions[$schemaExtension['schema']] = $schemaExtension['required']; |
||
178 | } |
||
179 | } |
||
180 | |||
181 | return $result; |
||
182 | } |
||
183 | } |
||
184 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.