| Total Complexity | 21 |
| Total Lines | 171 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | trait ExtendableAttributesTrait |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Extra (namespace qualified) attributes. |
||
| 31 | * |
||
| 32 | * @var list<\SimpleSAML\XML\Attribute> |
||
|
1 ignored issue
–
show
|
|||
| 33 | */ |
||
| 34 | protected array $namespacedAttributes = []; |
||
| 35 | |||
| 36 | |||
| 37 | /** |
||
| 38 | * Check if a namespace-qualified attribute exists. |
||
| 39 | * |
||
| 40 | * @param string|null $namespaceURI The namespace URI. |
||
| 41 | * @param string $localName The local name. |
||
| 42 | * @return bool true if the attribute exists, false if not. |
||
| 43 | */ |
||
| 44 | public function hasAttributeNS(?string $namespaceURI, string $localName): bool |
||
| 45 | { |
||
| 46 | foreach ($this->getAttributesNS() as $attr) { |
||
| 47 | if ($attr->getNamespaceURI() === $namespaceURI && $attr->getAttrName() === $localName) { |
||
| 48 | return true; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * Get a namespace-qualified attribute. |
||
| 57 | * |
||
| 58 | * @param string|null $namespaceURI The namespace URI. |
||
| 59 | * @param string $localName The local name. |
||
| 60 | * @return \SimpleSAML\XML\Attribute|null The value of the attribute, or null if the attribute does not exist. |
||
| 61 | */ |
||
| 62 | public function getAttributeNS(?string $namespaceURI, string $localName): ?Attribute |
||
| 63 | { |
||
| 64 | foreach ($this->getAttributesNS() as $attr) { |
||
| 65 | if ($attr->getNamespaceURI() === $namespaceURI && $attr->getAttrName() === $localName) { |
||
| 66 | return $attr; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | return null; |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the namespaced attributes in this element. |
||
| 75 | * |
||
| 76 | * @return list<\SimpleSAML\XML\Attribute> |
||
| 77 | */ |
||
| 78 | public function getAttributesNS(): array |
||
| 79 | { |
||
| 80 | return $this->namespacedAttributes; |
||
|
1 ignored issue
–
show
|
|||
| 81 | } |
||
| 82 | |||
| 83 | |||
| 84 | /** |
||
| 85 | * Parse an XML document and get the namespaced attributes. |
||
| 86 | * |
||
| 87 | * @param \DOMElement $xml |
||
| 88 | * |
||
| 89 | * @return list<\SimpleSAML\XML\Attribute> $attributes |
||
| 90 | */ |
||
| 91 | protected static function getAttributesNSFromXML(DOMElement $xml): array |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * @param list<\SimpleSAML\XML\Attribute> $attributes |
||
| 107 | * @throws \SimpleSAML\Assert\AssertionFailedException if $attributes contains anything other than Attribute objects |
||
| 108 | */ |
||
| 109 | protected function setAttributesNS(array $attributes): void |
||
| 110 | { |
||
| 111 | Assert::allIsInstanceOf( |
||
| 112 | $attributes, |
||
| 113 | Attribute::class, |
||
| 114 | 'Arbitrary XML attributes can only be an instance of Attribute.', |
||
| 115 | ); |
||
| 116 | $namespace = $this->getAttributeNamespace(); |
||
| 117 | |||
| 118 | // Validate namespace value |
||
| 119 | if (!is_array($namespace)) { |
||
| 120 | // Must be one of the predefined values |
||
| 121 | Assert::oneOf($namespace, C::XS_ANY_NS); |
||
| 122 | } else { |
||
| 123 | // Array must be non-empty and cannot contain ##any or ##other |
||
| 124 | Assert::notEmpty($namespace); |
||
| 125 | Assert::allNotSame($namespace, C::XS_ANY_NS_ANY); |
||
| 126 | Assert::allNotSame($namespace, C::XS_ANY_NS_OTHER); |
||
| 127 | } |
||
| 128 | |||
| 129 | // Get namespaces for all attributes |
||
| 130 | $actual_namespaces = array_map( |
||
| 131 | /** |
||
| 132 | * @param \SimpleSAML\XML\Attribute $elt |
||
| 133 | * @return string|null |
||
| 134 | */ |
||
| 135 | function (Attribute $attr) { |
||
| 136 | return $attr->getNamespaceURI(); |
||
| 137 | }, |
||
| 138 | $attributes, |
||
| 139 | ); |
||
| 140 | |||
| 141 | if ($namespace === C::XS_ANY_NS_LOCAL) { |
||
| 142 | // If ##local then all namespaces must be null |
||
| 143 | Assert::allNull($actual_namespaces); |
||
| 144 | } elseif (is_array($namespace)) { |
||
| 145 | // Make a local copy of the property that we can edit |
||
| 146 | $allowed_namespaces = $namespace; |
||
| 147 | |||
| 148 | // Replace the ##targetedNamespace with the actual namespace |
||
| 149 | if (($key = array_search(C::XS_ANY_NS_TARGET, $allowed_namespaces)) !== false) { |
||
| 150 | $allowed_namespaces[$key] = static::NS; |
||
|
1 ignored issue
–
show
|
|||
| 151 | } |
||
| 152 | |||
| 153 | // Replace the ##local with null |
||
| 154 | if (($key = array_search(C::XS_ANY_NS_LOCAL, $allowed_namespaces)) !== false) { |
||
| 155 | $allowed_namespaces[$key] = null; |
||
| 156 | } |
||
| 157 | |||
| 158 | $diff = array_diff($actual_namespaces, $allowed_namespaces); |
||
| 159 | Assert::isEmpty( |
||
| 160 | $diff, |
||
| 161 | sprintf( |
||
| 162 | 'Attributes from namespaces [ %s ] are not allowed inside a %s element.', |
||
| 163 | rtrim(implode(', ', $diff)), |
||
| 164 | static::NS, |
||
| 165 | ), |
||
| 166 | ); |
||
| 167 | } else { |
||
| 168 | // All elements must be namespaced, ergo non-null |
||
| 169 | Assert::allNotNull($actual_namespaces); |
||
| 170 | |||
| 171 | if ($namespace === C::XS_ANY_NS_OTHER) { |
||
| 172 | // Must be any namespace other than the parent element |
||
| 173 | Assert::allNotSame($actual_namespaces, static::NS); |
||
| 174 | } elseif ($namespace === C::XS_ANY_NS_TARGET) { |
||
| 175 | // Must be the same namespace as the one of the parent element |
||
| 176 | Assert::allSame($actual_namespaces, static::NS); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | $this->namespacedAttributes = $attributes; |
||
| 181 | } |
||
| 182 | |||
| 183 | |||
| 184 | |||
| 185 | /** |
||
| 186 | * @return array|string |
||
| 187 | */ |
||
| 188 | public function getAttributeNamespace(): array|string |
||
| 198 | } |
||
| 199 | } |
||
| 200 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths