Total Complexity | 42 |
Total Lines | 378 |
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 |
||
33 | final class Schema extends AbstractOpenAttrs implements SchemaValidatableElementInterface |
||
34 | { |
||
35 | use SchemaValidatableElementTrait; |
||
36 | |||
37 | |||
38 | /** @var string */ |
||
39 | public const LOCALNAME = 'schema'; |
||
40 | |||
41 | /** The exclusions for the xs:anyAttribute element */ |
||
42 | public const XS_ANY_ATTR_EXCLUSIONS = [ |
||
43 | [C_XML::NS_XML, 'lang'], |
||
44 | ]; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Schema constructor |
||
49 | * |
||
50 | * @param ( |
||
51 | * \SimpleSAML\XMLSchema\XML\XsInclude| |
||
52 | * \SimpleSAML\XMLSchema\XML\Import| |
||
53 | * \SimpleSAML\XMLSchema\XML\Redefine| |
||
54 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
55 | * )[] $topLevelElements |
||
56 | * @param ( |
||
57 | * \SimpleSAML\XMLSchema\XML\Interface\RedefinableInterface| |
||
58 | * \SimpleSAML\XMLSchema\XML\TopLevelAttribute| |
||
59 | * \SimpleSAML\XMLSchema\XML\TopLevelElement| |
||
60 | * \SimpleSAML\XMLSchema\XML\Notation| |
||
61 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
62 | * )[] $schemaTopElements |
||
63 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $targetNamespace |
||
64 | * @param \SimpleSAML\XMLSchema\Type\TokenValue $version |
||
65 | * @param \SimpleSAML\XMLSchema\Type\Schema\FullDerivationSetValue $finalDefault |
||
66 | * @param \SimpleSAML\XMLSchema\Type\Schema\BlockSetValue $blockDefault |
||
67 | * @param \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null $attributeFormDefault |
||
68 | * @param \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null $elementFormDefault |
||
69 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id |
||
70 | * @param \SimpleSAML\XML\Type\LangValue|null $lang |
||
71 | * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
||
72 | */ |
||
73 | public function __construct( |
||
74 | protected array $topLevelElements = [], |
||
75 | protected array $schemaTopElements = [], |
||
76 | protected ?AnyURIValue $targetNamespace = null, |
||
77 | protected ?TokenValue $version = null, |
||
78 | protected ?FullDerivationSetValue $finalDefault = null, |
||
79 | protected ?BlockSetValue $blockDefault = null, |
||
80 | protected ?FormChoiceValue $attributeFormDefault = null, |
||
81 | protected ?FormChoiceValue $elementFormDefault = null, |
||
82 | protected ?IDValue $id = null, |
||
83 | protected ?LangValue $lang = null, |
||
84 | array $namespacedAttributes = [], |
||
85 | ) { |
||
86 | Assert::maxCount($topLevelElements, C_XML::UNBOUNDED_LIMIT); |
||
87 | Assert::allIsInstanceOfAny( |
||
88 | $topLevelElements, |
||
89 | [XsInclude::class, Import::class, Redefine::class, Annotation::class], |
||
90 | SchemaViolationException::class, |
||
91 | ); |
||
92 | |||
93 | Assert::maxCount($schemaTopElements, C_XML::UNBOUNDED_LIMIT); |
||
94 | Assert::allIsInstanceOfAny( |
||
95 | $schemaTopElements, |
||
96 | [ |
||
97 | RedefinableInterface::class, |
||
98 | TopLevelAttribute::class, |
||
99 | TopLevelElement::class, |
||
100 | Notation::class, |
||
101 | Annotation::class, |
||
102 | ], |
||
103 | SchemaViolationException::class, |
||
104 | ); |
||
105 | |||
106 | parent::__construct($namespacedAttributes); |
||
107 | } |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Collect the value of the topLevelElements-property |
||
112 | * |
||
113 | * @return ( |
||
114 | * \SimpleSAML\XMLSchema\XML\XsInclude| |
||
115 | * \SimpleSAML\XMLSchema\XML\Import| |
||
116 | * \SimpleSAML\XMLSchema\XML\Redefine| |
||
117 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
118 | * )[] |
||
119 | */ |
||
120 | public function getTopLevelElements(): array |
||
121 | { |
||
122 | return $this->topLevelElements; |
||
123 | } |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Collect the value of the schemaTopElements-property |
||
128 | * |
||
129 | * @return ( |
||
130 | * \SimpleSAML\XMLSchema\XML\Interface\RedefinableInterface| |
||
131 | * \SimpleSAML\XMLSchema\XML\TopLevelAttribute| |
||
132 | * \SimpleSAML\XMLSchema\XML\TopLevelElement| |
||
133 | * \SimpleSAML\XMLSchema\XML\Notation| |
||
134 | * \SimpleSAML\XMLSchema\XML\Annotation |
||
135 | * )[] |
||
136 | */ |
||
137 | public function getSchemaTopElements(): array |
||
140 | } |
||
141 | |||
142 | |||
143 | /** |
||
144 | * Collect the value of the targetNamespace-property |
||
145 | * |
||
146 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
||
147 | */ |
||
148 | public function getTargetNamespace(): ?AnyURIValue |
||
149 | { |
||
150 | return $this->targetNamespace; |
||
151 | } |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Collect the value of the version-property |
||
156 | * |
||
157 | * @return \SimpleSAML\XMLSchema\Type\TokenValue|null |
||
158 | */ |
||
159 | public function getVersion(): ?TokenValue |
||
160 | { |
||
161 | return $this->version; |
||
162 | } |
||
163 | |||
164 | |||
165 | /** |
||
166 | * Collect the value of the blockDefault-property |
||
167 | * |
||
168 | * @return \SimpleSAML\XMLSchema\Type\Schema\BlockSetValue|null |
||
169 | */ |
||
170 | public function getBlockDefault(): ?BlockSetValue |
||
171 | { |
||
172 | return $this->blockDefault; |
||
173 | } |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Collect the value of the finalDefault-property |
||
178 | * |
||
179 | * @return \SimpleSAML\XMLSchema\Type\Schema\FullDerivationSetValue|null |
||
180 | */ |
||
181 | public function getFinalDefault(): ?FullDerivationSetValue |
||
182 | { |
||
183 | return $this->finalDefault; |
||
184 | } |
||
185 | |||
186 | |||
187 | /** |
||
188 | * Collect the value of the attributeFormDefault-property |
||
189 | * |
||
190 | * @return \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null |
||
191 | */ |
||
192 | public function getAttributeFormDefault(): ?FormChoiceValue |
||
193 | { |
||
194 | return $this->attributeFormDefault; |
||
195 | } |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Collect the value of the elementFormDefault-property |
||
200 | * |
||
201 | * @return \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null |
||
202 | */ |
||
203 | public function getElementFormDefault(): ?FormChoiceValue |
||
204 | { |
||
205 | return $this->elementFormDefault; |
||
206 | } |
||
207 | |||
208 | |||
209 | /** |
||
210 | * Collect the value of the id-property |
||
211 | * |
||
212 | * @return \SimpleSAML\XMLSchema\Type\IDValue|null |
||
213 | */ |
||
214 | public function getID(): ?IDValue |
||
215 | { |
||
216 | return $this->id; |
||
217 | } |
||
218 | |||
219 | |||
220 | /** |
||
221 | * Collect the value of the lang-property |
||
222 | * |
||
223 | * @return \SimpleSAML\XML\Type\LangValue|null |
||
224 | */ |
||
225 | public function getLang(): ?LangValue |
||
228 | } |
||
229 | |||
230 | |||
231 | /** |
||
232 | * Test if an object, at the state it's in, would produce an empty XML-element |
||
233 | * |
||
234 | * @return bool |
||
235 | */ |
||
236 | public function isEmptyElement(): bool |
||
249 | } |
||
250 | |||
251 | |||
252 | /** |
||
253 | * Create an instance of this object from its XML representation. |
||
254 | * |
||
255 | * @param \DOMElement $xml |
||
256 | * @return static |
||
257 | * |
||
258 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
259 | * if the qualified name of the supplied element is wrong |
||
260 | */ |
||
261 | public static function fromXML(DOMElement $xml): static |
||
358 | ); |
||
359 | } |
||
360 | |||
361 | |||
362 | /** |
||
363 | * Add this Schema to an XML element. |
||
364 | * |
||
365 | * @param \DOMElement|null $parent The element we should append this Schema to. |
||
366 | * @return \DOMElement |
||
367 | */ |
||
368 | public function toXML(?DOMElement $parent = null): DOMElement |
||
413 |