| Total Complexity | 47 | 
| Total Lines | 294 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like AbstractElement 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 AbstractElement, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 20 | abstract class AbstractElement extends AbstractAnnotated  | 
            ||
| 21 | { | 
            ||
| 22 | use DefRefTrait;  | 
            ||
| 23 | use OccursTrait;  | 
            ||
| 24 | |||
| 25 | /**  | 
            ||
| 26 | * Element constructor  | 
            ||
| 27 | *  | 
            ||
| 28 | * @param \SimpleSAML\XMLSchema\Type\Builtin\NCNameValue|null $name  | 
            ||
| 29 | * @param \SimpleSAML\XMLSchema\Type\Builtin\QNameValue|null $reference  | 
            ||
| 30 | * @param \SimpleSAML\XMLSchema\XML\xs\LocalSimpleType|\SimpleSAML\XMLSchema\XML\xs\LocalComplexType|null $localType  | 
            ||
| 31 | * @param array<\SimpleSAML\XMLSchema\XML\xs\IdentityConstraintInterface> $identityConstraint  | 
            ||
| 32 | * @param \SimpleSAML\XMLSchema\Type\Builtin\QNameValue|null $type  | 
            ||
| 33 | * @param \SimpleSAML\XMLSchema\Type\Builtin\QNameValue|null $substitutionGroup  | 
            ||
| 34 | * @param \SimpleSAML\XMLSchema\Type\MinOccursValue|null $minOccurs  | 
            ||
| 35 | * @param \SimpleSAML\XMLSchema\Type\MaxOccursValue|null $maxOccurs  | 
            ||
| 36 | * @param \SimpleSAML\XMLSchema\Type\Builtin\StringValue|null $default  | 
            ||
| 37 | * @param \SimpleSAML\XMLSchema\Type\Builtin\StringValue|null $fixed  | 
            ||
| 38 | * @param \SimpleSAML\XMLSchema\Type\Builtin\BooleanValue|null $nillable  | 
            ||
| 39 | * @param \SimpleSAML\XMLSchema\Type\Builtin\BooleanValue|null $abstract  | 
            ||
| 40 | * @param \SimpleSAML\XMLSchema\Type\DerivationSetValue|null $final  | 
            ||
| 41 | * @param \SimpleSAML\XMLSchema\Type\BlockSetValue|null $block  | 
            ||
| 42 | * @param \SimpleSAML\XMLSchema\Type\FormChoiceValue|null $form  | 
            ||
| 43 | * @param \SimpleSAML\XMLSchema\XML\xs\Annotation|null $annotation  | 
            ||
| 44 | * @param \SimpleSAML\XMLSchema\Type\Builtin\IDValue|null $id  | 
            ||
| 45 | * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes  | 
            ||
| 46 | */  | 
            ||
| 47 | public function __construct(  | 
            ||
| 48 | ?NCNameValue $name = null,  | 
            ||
| 49 | ?QNameValue $reference = null,  | 
            ||
| 50 | protected LocalSimpleType|LocalComplexType|null $localType = null,  | 
            ||
| 51 | protected array $identityConstraint = [],  | 
            ||
| 52 | protected ?QNameValue $type = null,  | 
            ||
| 53 | protected ?QNameValue $substitutionGroup = null,  | 
            ||
| 54 | ?MinOccursValue $minOccurs = null,  | 
            ||
| 55 | ?MaxOccursValue $maxOccurs = null,  | 
            ||
| 56 | protected ?StringValue $default = null,  | 
            ||
| 57 | protected ?StringValue $fixed = null,  | 
            ||
| 58 | protected ?BooleanValue $nillable = null,  | 
            ||
| 59 | protected ?BooleanValue $abstract = null,  | 
            ||
| 60 | protected ?DerivationSetValue $final = null,  | 
            ||
| 61 | protected ?BlockSetValue $block = null,  | 
            ||
| 62 | protected ?FormChoiceValue $form = null,  | 
            ||
| 63 | ?Annotation $annotation = null,  | 
            ||
| 64 | ?IDValue $id = null,  | 
            ||
| 65 | array $namespacedAttributes = [],  | 
            ||
| 66 |     ) { | 
            ||
| 67 | Assert::allIsInstanceOf(  | 
            ||
| 68 | $identityConstraint,  | 
            ||
| 69 | IdentityConstraintInterface::class,  | 
            ||
| 70 | SchemaViolationException::class,  | 
            ||
| 71 | );  | 
            ||
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * An element is declared by either: a name and a type (either nested or referenced via the type attribute)  | 
            ||
| 75 | * or a ref to an existing element declaration  | 
            ||
| 76 | *  | 
            ||
| 77 | * type and ref are mutually exclusive.  | 
            ||
| 78 | * name and ref are mutually exclusive, one is required  | 
            ||
| 79 | */  | 
            ||
| 80 | Assert::true(is_null($type) || is_null($reference), ProtocolViolationException::class);  | 
            ||
| 81 | Assert::true(is_null($name) || is_null($reference), ProtocolViolationException::class);  | 
            ||
| 82 | Assert::false(is_null($name) && is_null($reference), ProtocolViolationException::class);  | 
            ||
| 83 | |||
| 84 | /**  | 
            ||
| 85 | * default and fixed are mutually exclusive  | 
            ||
| 86 | */  | 
            ||
| 87 | Assert::true(is_null($default) || is_null($fixed), ProtocolViolationException::class);  | 
            ||
| 88 | |||
| 89 | parent::__construct($annotation, $id, $namespacedAttributes);  | 
            ||
| 90 | |||
| 91 | $this->setName($name);  | 
            ||
| 92 | $this->setReference($reference);  | 
            ||
| 93 | $this->setMinOccurs($minOccurs);  | 
            ||
| 94 | $this->setMaxOccurs($maxOccurs);  | 
            ||
| 95 | }  | 
            ||
| 96 | |||
| 97 | |||
| 98 | /**  | 
            ||
| 99 | * Collect the value of the localType-property  | 
            ||
| 100 | *  | 
            ||
| 101 | * @return \SimpleSAML\XMLSchema\XML\xs\LocalSimpleType|\SimpleSAML\XMLSchema\XML\xs\LocalComplexType|null  | 
            ||
| 102 | */  | 
            ||
| 103 | public function getLocalType(): LocalSimpleType|LocalComplexType|null  | 
            ||
| 104 |     { | 
            ||
| 105 | return $this->localType;  | 
            ||
| 106 | }  | 
            ||
| 107 | |||
| 108 | |||
| 109 | /**  | 
            ||
| 110 | * Collect the value of the identityConstraint-property  | 
            ||
| 111 | *  | 
            ||
| 112 | * @return array<\SimpleSAML\XMLSchema\XML\xs\IdentityConstraintInterface>  | 
            ||
| 113 | */  | 
            ||
| 114 | public function getIdentityConstraint(): array  | 
            ||
| 115 |     { | 
            ||
| 116 | return $this->identityConstraint;  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 | |||
| 120 | /**  | 
            ||
| 121 | * Collect the value of the type-property  | 
            ||
| 122 | *  | 
            ||
| 123 | * @return \SimpleSAML\XMLSchema\Type\Builtin\QNameValue|null  | 
            ||
| 124 | */  | 
            ||
| 125 | public function getType(): ?QNameValue  | 
            ||
| 126 |     { | 
            ||
| 127 | return $this->type;  | 
            ||
| 128 | }  | 
            ||
| 129 | |||
| 130 | |||
| 131 | /**  | 
            ||
| 132 | * Collect the value of the substitutionGroup-property  | 
            ||
| 133 | *  | 
            ||
| 134 | * @return \SimpleSAML\XMLSchema\Type\Builtin\QNameValue|null  | 
            ||
| 135 | */  | 
            ||
| 136 | public function getSubstitutionGroup(): ?QNameValue  | 
            ||
| 137 |     { | 
            ||
| 138 | return $this->substitutionGroup;  | 
            ||
| 139 | }  | 
            ||
| 140 | |||
| 141 | |||
| 142 | /**  | 
            ||
| 143 | * Collect the value of the default-property  | 
            ||
| 144 | *  | 
            ||
| 145 | * @return \SimpleSAML\XMLSchema\Type\Builtin\StringValue|null  | 
            ||
| 146 | */  | 
            ||
| 147 | public function getDefault(): ?StringValue  | 
            ||
| 148 |     { | 
            ||
| 149 | return $this->default;  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 | |||
| 153 | /**  | 
            ||
| 154 | * Collect the value of the fixed-property  | 
            ||
| 155 | *  | 
            ||
| 156 | * @return \SimpleSAML\XMLSchema\Type\Builtin\StringValue|null  | 
            ||
| 157 | */  | 
            ||
| 158 | public function getFixed(): ?StringValue  | 
            ||
| 159 |     { | 
            ||
| 160 | return $this->fixed;  | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 | |||
| 164 | /**  | 
            ||
| 165 | * Collect the value of the nillable-property  | 
            ||
| 166 | *  | 
            ||
| 167 | * @return \SimpleSAML\XMLSchema\Type\Builtin\BooleanValue|null  | 
            ||
| 168 | */  | 
            ||
| 169 | public function getNillable(): ?BooleanValue  | 
            ||
| 170 |     { | 
            ||
| 171 | return $this->nillable;  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 | |||
| 175 | /**  | 
            ||
| 176 | * Collect the value of the abstract-property  | 
            ||
| 177 | *  | 
            ||
| 178 | * @return \SimpleSAML\XMLSchema\Type\Builtin\BooleanValue|null  | 
            ||
| 179 | */  | 
            ||
| 180 | public function getAbstract(): ?BooleanValue  | 
            ||
| 181 |     { | 
            ||
| 182 | return $this->abstract;  | 
            ||
| 183 | }  | 
            ||
| 184 | |||
| 185 | |||
| 186 | /**  | 
            ||
| 187 | * Collect the value of the final-property  | 
            ||
| 188 | *  | 
            ||
| 189 | * @return \SimpleSAML\XMLSchema\Type\DerivationSetValue|null  | 
            ||
| 190 | */  | 
            ||
| 191 | public function getFinal(): ?DerivationSetValue  | 
            ||
| 192 |     { | 
            ||
| 193 | return $this->final;  | 
            ||
| 194 | }  | 
            ||
| 195 | |||
| 196 | |||
| 197 | /**  | 
            ||
| 198 | * Collect the value of the block-property  | 
            ||
| 199 | *  | 
            ||
| 200 | * @return \SimpleSAML\XMLSchema\Type\BlockSetValue|null  | 
            ||
| 201 | */  | 
            ||
| 202 | public function getBlock(): ?BlockSetValue  | 
            ||
| 203 |     { | 
            ||
| 204 | return $this->block;  | 
            ||
| 205 | }  | 
            ||
| 206 | |||
| 207 | |||
| 208 | /**  | 
            ||
| 209 | * Collect the value of the form-property  | 
            ||
| 210 | *  | 
            ||
| 211 | * @return \SimpleSAML\XMLSchema\Type\FormChoiceValue|null  | 
            ||
| 212 | */  | 
            ||
| 213 | public function getForm(): ?FormChoiceValue  | 
            ||
| 214 |     { | 
            ||
| 215 | return $this->form;  | 
            ||
| 216 | }  | 
            ||
| 217 | |||
| 218 | |||
| 219 | /**  | 
            ||
| 220 | * Test if an object, at the state it's in, would produce an empty XML-element  | 
            ||
| 221 | *  | 
            ||
| 222 | * @return bool  | 
            ||
| 223 | */  | 
            ||
| 224 | public function isEmptyElement(): bool  | 
            ||
| 242 | }  | 
            ||
| 243 | |||
| 244 | |||
| 245 | /**  | 
            ||
| 246 | * Add this Annotated to an XML element.  | 
            ||
| 247 | *  | 
            ||
| 248 | * @param \DOMElement|null $parent The element we should append this Annotated to.  | 
            ||
| 249 | * @return \DOMElement  | 
            ||
| 250 | */  | 
            ||
| 251 | public function toXML(?DOMElement $parent = null): DOMElement  | 
            ||
| 252 |     { | 
            ||
| 253 | $e = parent::toXML($parent);  | 
            ||
| 314 | }  | 
            ||
| 315 | }  | 
            ||
| 316 |