Total Complexity | 42 |
Total Lines | 379 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Schema often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Schema, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | final class Schema extends AbstractOpenAttrs implements SchemaValidatableElementInterface |
||
27 | { |
||
28 | use SchemaValidatableElementTrait; |
||
1 ignored issue
–
show
|
|||
29 | |||
30 | /** @var string */ |
||
31 | public const LOCALNAME = 'schema'; |
||
32 | |||
33 | /** The exclusions for the xs:anyAttribute element */ |
||
34 | public const XS_ANY_ATTR_EXCLUSIONS = [ |
||
35 | [C::NS_XML, 'lang'], |
||
36 | ]; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Schema constructor |
||
41 | * |
||
42 | * @param ( |
||
43 | * \SimpleSAML\XMLSchema\XML\XsInclude| |
||
44 | * \SimpleSAML\XMLSchema\XML\Import| |
||
45 | * \SimpleSAML\XMLSchema\XML\Redefine| |
||
46 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
47 | * )[] $topLevelElements |
||
48 | * @param ( |
||
49 | * \SimpleSAML\XMLSchema\XML\Interface\RedefinableInterface| |
||
50 | * \SimpleSAML\XMLSchema\XML\TopLevelAttribute| |
||
51 | * \SimpleSAML\XMLSchema\XML\TopLevelElement| |
||
52 | * \SimpleSAML\XMLSchema\XML\Notation| |
||
53 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
54 | * )[] $schemaTopElements |
||
55 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $targetNamespace |
||
56 | * @param \SimpleSAML\XMLSchema\Type\TokenValue $version |
||
57 | * @param \SimpleSAML\XMLSchema\Type\Schema\FullDerivationSetValue $finalDefault |
||
58 | * @param \SimpleSAML\XMLSchema\Type\Schema\BlockSetValue $blockDefault |
||
59 | * @param \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null $attributeFormDefault |
||
60 | * @param \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null $elementFormDefault |
||
61 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id |
||
62 | * @param \SimpleSAML\XML\Type\LangValue|null $lang |
||
63 | * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
||
64 | */ |
||
65 | public function __construct( |
||
66 | protected array $topLevelElements = [], |
||
67 | protected array $schemaTopElements = [], |
||
68 | protected ?AnyURIValue $targetNamespace = null, |
||
69 | protected ?TokenValue $version = null, |
||
70 | protected ?FullDerivationSetValue $finalDefault = null, |
||
71 | protected ?BlockSetValue $blockDefault = null, |
||
72 | protected ?FormChoiceValue $attributeFormDefault = null, |
||
73 | protected ?FormChoiceValue $elementFormDefault = null, |
||
74 | protected ?IDValue $id = null, |
||
75 | protected ?LangValue $lang = null, |
||
76 | array $namespacedAttributes = [], |
||
77 | ) { |
||
78 | Assert::maxCount($topLevelElements, C::UNBOUNDED_LIMIT); |
||
79 | Assert::allIsInstanceOfAny( |
||
80 | $topLevelElements, |
||
81 | [XsInclude::class, Import::class, Redefine::class, Annotation::class], |
||
82 | SchemaViolationException::class, |
||
83 | ); |
||
84 | |||
85 | Assert::maxCount($schemaTopElements, C::UNBOUNDED_LIMIT); |
||
86 | Assert::allIsInstanceOfAny( |
||
87 | $schemaTopElements, |
||
88 | [ |
||
89 | RedefinableInterface::class, |
||
90 | TopLevelAttribute::class, |
||
91 | TopLevelElement::class, |
||
92 | Notation::class, |
||
93 | Annotation::class, |
||
94 | ], |
||
95 | SchemaViolationException::class, |
||
96 | ); |
||
97 | |||
98 | parent::__construct($namespacedAttributes); |
||
99 | } |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Collect the value of the topLevelElements-property |
||
104 | * |
||
105 | * @return ( |
||
1 ignored issue
–
show
|
|||
106 | * \SimpleSAML\XMLSchema\XML\XsInclude| |
||
107 | * \SimpleSAML\XMLSchema\XML\Import| |
||
108 | * \SimpleSAML\XMLSchema\XML\Redefine| |
||
109 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
110 | * )[] |
||
111 | */ |
||
112 | public function getTopLevelElements(): array |
||
113 | { |
||
114 | return $this->topLevelElements; |
||
115 | } |
||
116 | |||
117 | |||
118 | /** |
||
119 | * Collect the value of the schemaTopElements-property |
||
120 | * |
||
121 | * @return ( |
||
1 ignored issue
–
show
|
|||
122 | * \SimpleSAML\XMLSchema\XML\Interface\RedefinableInterface| |
||
123 | * \SimpleSAML\XMLSchema\XML\TopLevelAttribute| |
||
124 | * \SimpleSAML\XMLSchema\XML\TopLevelElement| |
||
125 | * \SimpleSAML\XMLSchema\XML\Notation| |
||
126 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
127 | * )[] |
||
128 | */ |
||
129 | public function getSchemaTopElements(): array |
||
132 | } |
||
133 | |||
134 | |||
135 | /** |
||
136 | * Collect the value of the targetNamespace-property |
||
137 | * |
||
138 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
||
139 | */ |
||
140 | public function getTargetNamespace(): ?AnyURIValue |
||
141 | { |
||
142 | return $this->targetNamespace; |
||
143 | } |
||
144 | |||
145 | |||
146 | /** |
||
147 | * Collect the value of the version-property |
||
148 | * |
||
149 | * @return \SimpleSAML\XMLSchema\Type\TokenValue|null |
||
150 | */ |
||
151 | public function getVersion(): ?TokenValue |
||
152 | { |
||
153 | return $this->version; |
||
154 | } |
||
155 | |||
156 | |||
157 | /** |
||
158 | * Collect the value of the blockDefault-property |
||
159 | * |
||
160 | * @return \SimpleSAML\XMLSchema\Type\Schema\BlockSetValue|null |
||
161 | */ |
||
162 | public function getBlockDefault(): ?BlockSetValue |
||
163 | { |
||
164 | return $this->blockDefault; |
||
165 | } |
||
166 | |||
167 | |||
168 | /** |
||
169 | * Collect the value of the finalDefault-property |
||
170 | * |
||
171 | * @return \SimpleSAML\XMLSchema\Type\Schema\FullDerivationSetValue|null |
||
172 | */ |
||
173 | public function getFinalDefault(): ?FullDerivationSetValue |
||
174 | { |
||
175 | return $this->finalDefault; |
||
176 | } |
||
177 | |||
178 | |||
179 | /** |
||
180 | * Collect the value of the attributeFormDefault-property |
||
181 | * |
||
182 | * @return \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null |
||
183 | */ |
||
184 | public function getAttributeFormDefault(): ?FormChoiceValue |
||
185 | { |
||
186 | return $this->attributeFormDefault; |
||
187 | } |
||
188 | |||
189 | |||
190 | /** |
||
191 | * Collect the value of the elementFormDefault-property |
||
192 | * |
||
193 | * @return \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null |
||
194 | */ |
||
195 | public function getElementFormDefault(): ?FormChoiceValue |
||
196 | { |
||
197 | return $this->elementFormDefault; |
||
198 | } |
||
199 | |||
200 | |||
201 | /** |
||
202 | * Collect the value of the id-property |
||
203 | * |
||
204 | * @return \SimpleSAML\XMLSchema\Type\IDValue|null |
||
205 | */ |
||
206 | public function getID(): ?IDValue |
||
207 | { |
||
208 | return $this->id; |
||
209 | } |
||
210 | |||
211 | |||
212 | /** |
||
213 | * Collect the value of the lang-property |
||
214 | * |
||
215 | * @return \SimpleSAML\XML\Type\LangValue|null |
||
216 | */ |
||
217 | public function getLang(): ?LangValue |
||
218 | { |
||
219 | return $this->lang; |
||
220 | } |
||
221 | |||
222 | |||
223 | /** |
||
224 | * Test if an object, at the state it's in, would produce an empty XML-element |
||
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | public function isEmptyElement(): bool |
||
229 | { |
||
230 | return parent::isEmptyElement() && |
||
231 | empty($this->getTopLevelElements()) && |
||
232 | empty($this->getSchemaTopElements()) && |
||
233 | empty($this->getTargetNamespace()) && |
||
234 | empty($this->getVersion()) && |
||
235 | empty($this->getFinalDefault()) && |
||
236 | empty($this->getBlockDefault()) && |
||
237 | empty($this->getAttributeFormDefault()) && |
||
238 | empty($this->getElementFormDefault()) && |
||
239 | empty($this->getId()) && |
||
240 | empty($this->getLang()); |
||
241 | } |
||
242 | |||
243 | |||
244 | /** |
||
245 | * Create an instance of this object from its XML representation. |
||
246 | * |
||
247 | * @param \DOMElement $xml |
||
248 | * @return static |
||
249 | * |
||
250 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
251 | * if the qualified name of the supplied element is wrong |
||
252 | */ |
||
253 | public static function fromXML(DOMElement $xml): static |
||
352 | ); |
||
353 | } |
||
354 | |||
355 | |||
356 | /** |
||
357 | * Add this Schema to an XML element. |
||
358 | * |
||
359 | * @param \DOMElement|null $parent The element we should append this Schema to. |
||
360 | * @return \DOMElement |
||
361 | */ |
||
362 | public function toXML(?DOMElement $parent = null): DOMElement |
||
405 | } |
||
406 | } |
||
407 |