Skip to content

Commit

Permalink
Start using PHP 8.1 features
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 18, 2023
1 parent a9d4609 commit 1432cef
Show file tree
Hide file tree
Showing 25 changed files with 123 additions and 86 deletions.
40 changes: 0 additions & 40 deletions src/SAML2/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,6 @@ class Constants extends \SimpleSAML\XMLSecurity\Constants
*/
public const CM_VOUCHES = 'urn:oasis:names:tc:SAML:2.0:cm:sender-vouches';

/**
* Request Authentication Context Comparison indicating that the resulting authentication context in the
* authentication statement MUST be stronger (as deemed by the responder) than any one of the authentication
* contexts specified
*/
public const COMPARISON_BETTER = 'better';

/**
* Request Authentication Context Comparison indicating that the resulting authentication context in the
* authentication statement MUST be the exact match of at least one of the authentication contexts specified
*/
public const COMPARISON_EXACT = 'exact';

/**
* Request Authentication Context Comparison indicating that the resulting authentication context in the
* authentication statement MUST be as strong as possible (as deemed by the responder) without exceeding the
* strength of at least one of the authentication contexts specified.
*/
public const COMPARISON_MAXIMUM = 'maximum';

/**
* Request Authentication Context Comparison indicating that he resulting authentication context in the
* authentication statement MUST be at least as strong (as deemed by the responder) as one of the authentication
* contexts specified.
*/
public const COMPARISON_MINIMUM = 'minimum';

/**
* Indicates that a principal’s consent has been explicitly obtained by the issuer of the message during the
* action that initiated the message.
Expand Down Expand Up @@ -498,17 +471,4 @@ class Constants extends \SimpleSAML\XMLSecurity\Constants
* The format to express a timestamp in SAML2
*/
public const DATETIME_FORMAT = 'Y-m-d\\TH:i:sp';

/**
* Valid values for saml:DecisionType
*/
public const AUTHZ_DECISION_PERMIT = 'Permit';
public const AUTHZ_DECISION_DENY = 'Deny';
public const AUTHZ_DECISION_INDETERMINATE = 'Indeterminate';

public const AUTHZ_DECISIONS = [
self::AUTHZ_DECISION_PERMIT,
self::AUTHZ_DECISION_DENY,
self::AUTHZ_DECISION_INDETERMINATE,
];
}
35 changes: 35 additions & 0 deletions src/SAML2/XML/Comparison.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML2\XML;

enum Comparison: string
{
/**
* Request Authentication Context Comparison indicating that the resulting authentication context in the
* authentication statement MUST be stronger (as deemed by the responder) than any one of the authentication
* contexts specified
*/
case BETTER = 'better';

/**
* Request Authentication Context Comparison indicating that the resulting authentication context in the
* authentication statement MUST be the exact match of at least one of the authentication contexts specified
*/
case EXACT = 'exact';

/**
* Request Authentication Context Comparison indicating that the resulting authentication context in the
* authentication statement MUST be as strong as possible (as deemed by the responder) without exceeding the
* strength of at least one of the authentication contexts specified.
*/
case MAXIMUM = 'maximum';

/**
* Request Authentication Context Comparison indicating that he resulting authentication context in the
* authentication statement MUST be at least as strong (as deemed by the responder) as one of the authentication
* contexts specified.
*/
case MINIMUM = 'minimum';
}
15 changes: 15 additions & 0 deletions src/SAML2/XML/Decision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML2\XML;

/**
* Valid values for saml:DecisionType
*/
enum Decision: string
{
case PERMIT = 'Permit';
case DENY = 'Deny';
case INDETERMINATE = 'Indeterminate';
}
4 changes: 2 additions & 2 deletions src/SAML2/XML/alg/DigestMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;

/**
Expand All @@ -25,7 +25,7 @@ final class DigestMethod extends AbstractAlgElement
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_ANY;
public const XS_ANY_ELT_NAMESPACE = NS::ANY;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/SAML2/XML/alg/SigningMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use SimpleSAML\XML\Exception\MissingAttributeException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;

use function strval;
Expand All @@ -28,7 +28,7 @@ final class SigningMethod extends AbstractAlgElement
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_ANY;
public const XS_ANY_ELT_NAMESPACE = NS::ANY;


/**
Expand Down
9 changes: 5 additions & 4 deletions src/SAML2/XML/md/AbstractEndpointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace SimpleSAML\SAML2\XML\md;

use CASE_LOWER;
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Exception\ArrayValidationException;
use SimpleSAML\XML\ArrayizableElementInterface;
use SimpleSAML\XML\Attribute as XMLAttribute;
Expand All @@ -16,6 +16,7 @@
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;

use function array_change_key_case;
use function array_key_exists;
Expand Down Expand Up @@ -43,10 +44,10 @@ abstract class AbstractEndpointType extends AbstractMdElement implements Arrayiz
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down Expand Up @@ -139,7 +140,7 @@ public static function fromXML(DOMElement $xml): static
foreach ($xml->childNodes as $child) {
if (!($child instanceof DOMElement)) {
continue;
} elseif ($child->namespaceURI !== C::NS_MD) {
} elseif ($child->namespaceURI !== static::NS) {
$children[] = new Chunk($child);
} // else continue
}
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/md/AbstractRoleDescriptorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;

use function implode;

Expand All @@ -23,7 +24,7 @@ abstract class AbstractRoleDescriptorType extends AbstractMetadataDocument
use ExtendableAttributesTrait;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/md/AffiliationDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\XML\ds\Signature;

/**
Expand All @@ -26,7 +27,7 @@ final class AffiliationDescriptor extends AbstractMetadataDocument
use ExtendableAttributesTrait;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/md/ContactPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\Utils as XMLUtils;
use SimpleSAML\XML\XsNamespace as NS;

use function array_filter;
use function array_change_key_case;
Expand All @@ -43,7 +44,7 @@ final class ContactPerson extends AbstractMdElement implements ArrayizableElemen
use ExtendableElementTrait;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/md/EntityDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\XML\ds\Signature;

use function is_null;
Expand All @@ -27,7 +28,7 @@ final class EntityDescriptor extends AbstractMetadataDocument
use ExtendableAttributesTrait;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down
4 changes: 3 additions & 1 deletion src/SAML2/XML/md/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SimpleSAML\SAML2\XML\md;

use CASE_LOWER;
use DOMDocument;
use DOMElement;
use Exception;
Expand All @@ -20,6 +21,7 @@
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\Utils as XMLUtils;
use SimpleSAML\XML\XsNamespace as NS;

use function array_change_key_case;
use function array_filter;
Expand All @@ -38,7 +40,7 @@ final class Organization extends AbstractMdElement implements ArrayizableElement
use ExtendableElementTrait;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/mdui/DiscoHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;

use function array_filter;
use function array_key_exists;
Expand All @@ -30,7 +31,7 @@ final class DiscoHints extends AbstractMduiElement implements ArrayizableElement
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;


/**
Expand Down
4 changes: 3 additions & 1 deletion src/SAML2/XML/mdui/UIInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SimpleSAML\SAML2\XML\mdui;

use CASE_LOWER;
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Exception\ArrayValidationException;
Expand All @@ -15,6 +16,7 @@
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;

use function array_filter;
use function array_key_exists;
Expand All @@ -34,7 +36,7 @@ final class UIInfo extends AbstractMduiElement implements ArrayizableElementInte
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;

/**
* Create a UIInfo element.
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/saml/Advice.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\XsNamespace as NS;

/**
* Class representing a saml:Advice element.
Expand All @@ -22,7 +23,7 @@ final class Advice extends AbstractSamlElement
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;


/**
Expand Down
3 changes: 2 additions & 1 deletion src/SAML2/XML/saml/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
Expand All @@ -25,7 +26,7 @@ class Attribute extends AbstractSamlElement implements EncryptableElementInterfa
use ExtendableAttributesTrait;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_OTHER;
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
Expand Down
8 changes: 4 additions & 4 deletions src/SAML2/XML/saml/AuthnContextDecl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\XsNamespace as NS;

/**
* Class representing SAML2 AuthnContextDecl
Expand All @@ -24,10 +24,10 @@ final class AuthnContextDecl extends AbstractSamlElement
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_ANY;
public const XS_ANY_ELT_NAMESPACE = NS::ANY;

/** The namespace-attribute for the xs:anyAttribute element */
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_ANY;
public const XS_ANY_ATTR_NAMESPACE = NS::ANY;


/**
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function fromXML(DOMElement $xml): static

$elements = [];
foreach ($xml->childNodes as $element) {
if ($element->namespaceURI === C::NS_SAML) {
if ($element->namespaceURI === static::NS) {
continue;
} elseif (!($element instanceof DOMElement)) {
continue;
Expand Down
Loading

0 comments on commit 1432cef

Please sign in to comment.