| Conditions | 2 |
| Paths | 2 |
| Total Lines | 60 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 37 | public function __construct( |
||
| 38 | protected array $children, |
||
| 39 | ) { |
||
| 40 | Assert::allIsInstanceOfAny($children, [Assertion::class, Attribute::class]); |
||
| 41 | |||
| 42 | $assertions = array_filter($children, function ($child) { |
||
| 43 | return $child instanceof Assertion; |
||
| 44 | }); |
||
| 45 | |||
| 46 | foreach ($assertions as $assertion) { |
||
| 47 | $statements = array_merge( |
||
| 48 | $assertion->getAttributeStatements(), |
||
| 49 | $assertion->getAuthnStatements(), |
||
| 50 | $assertion->getStatements(), |
||
| 51 | ); |
||
| 52 | |||
| 53 | Assert::allIsInstanceOf( |
||
| 54 | $statements, |
||
| 55 | AttributeStatement::class, |
||
| 56 | '<saml:Asssertion> elements in an <mdattr:EntityAttributes> may only contain AttributeStatements', |
||
| 57 | ProtocolViolationException::class, |
||
| 58 | ); |
||
| 59 | Assert::count( |
||
| 60 | $statements, |
||
| 61 | 1, |
||
| 62 | 'One (and only one) <saml:AttributeStatement> MUST be included ' |
||
| 63 | . 'in a <saml:Assertion> inside a <mdattr:EntityAttribute>', |
||
| 64 | ProtocolViolationException::class, |
||
| 65 | ); |
||
| 66 | Assert::notNull( |
||
| 67 | Assertion::fromXML($assertion->toXML())->getSignature(), |
||
| 68 | 'Every <saml:Assertion> inside a <mdattr:EntityAttributes> must be individually signed', |
||
| 69 | ProtocolViolationException::class, |
||
| 70 | ); |
||
| 71 | |||
| 72 | $subject = $assertion->getSubject(); |
||
| 73 | Assert::notNull( |
||
| 74 | $subject, |
||
| 75 | 'Every <saml:Assertion> inside a <mdattr:EntityAttributes> must contain a Subject', |
||
| 76 | ProtocolViolationException::class, |
||
| 77 | ); |
||
| 78 | |||
| 79 | Assert::isEmpty( |
||
| 80 | $subject?->getSubjectConfirmation(), |
||
| 81 | 'Every <saml:Assertion> inside a <mdattr:EntityAttributes> must NOT contain any SubjectConfirmation', |
||
| 82 | ProtocolViolationException::class, |
||
| 83 | ); |
||
| 84 | |||
| 85 | $nameId = $subject?->getIdentifier(); |
||
| 86 | Assert::isInstanceOf( |
||
| 87 | $nameId, |
||
| 88 | NameID::class, |
||
| 89 | 'Every <saml:Assertion> inside a <mdattr:EntityAttributes> must contain a NameID', |
||
| 90 | ProtocolViolationException::class, |
||
| 91 | ); |
||
| 92 | Assert::same( |
||
| 93 | $nameId?->getFormat(), |
||
| 94 | C::NAMEID_ENTITY, |
||
| 95 | sprintf('The NameID format must be %s', C::NAMEID_ENTITY), |
||
| 96 | ProtocolViolationException::class, |
||
| 97 | ); |
||
| 177 |