| Conditions | 10 |
| Paths | 10 |
| Total Lines | 99 |
| Code Lines | 41 |
| 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 |
||
| 50 | public function __construct( |
||
| 51 | protected array $entityDescriptors = [], |
||
| 52 | protected array $entitiesDescriptors = [], |
||
| 53 | protected ?SAMLStringValue $Name = null, |
||
| 54 | ?IDValue $ID = null, |
||
| 55 | ?SAMLDateTimeValue $validUntil = null, |
||
| 56 | ?DurationValue $cacheDuration = null, |
||
| 57 | ?Extensions $extensions = null, |
||
| 58 | ) { |
||
| 59 | Assert::true( |
||
| 60 | !empty($entitiesDescriptors) || !empty($entityDescriptors), |
||
| 61 | 'At least one md:EntityDescriptor or md:EntitiesDescriptor element is required.', |
||
| 62 | ProtocolViolationException::class, |
||
| 63 | ); |
||
| 64 | Assert::maxCount($entitiesDescriptors, C::UNBOUNDED_LIMIT); |
||
| 65 | Assert::maxCount($entityDescriptors, C::UNBOUNDED_LIMIT); |
||
| 66 | Assert::allIsInstanceOf($entitiesDescriptors, EntitiesDescriptor::class); |
||
| 67 | Assert::allIsInstanceOf($entityDescriptors, EntityDescriptor::class); |
||
| 68 | |||
| 69 | if ($extensions !== null) { |
||
| 70 | /** |
||
| 71 | * When a <mdrpi:RegistrationInfo> element appears in the <md:Extensions> element of a |
||
| 72 | * <md:EntitiesDescriptor> element it applies to all descendant <md:EntitiesDescriptor> and |
||
| 73 | * <md:EntityDescriptor> elements. That is to say, this is equivalent to putting an identical |
||
| 74 | * <mdrpi:RegistrationInfo> on every descendant <md:EntityDescriptor>. When used in this |
||
| 75 | * manner, descendant <md:EntitiesDescriptor> and <md:EntityDescriptor> elements MUST |
||
| 76 | * NOT contain a <mdrpi:RegistrationInfo> element in their <md:Extensions> element. |
||
| 77 | */ |
||
| 78 | $toplevel_regInfo = array_values(array_filter($extensions->getList(), function ($ext) { |
||
| 79 | return $ext instanceof RegistrationInfo; |
||
| 80 | })); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * The <mdrpi:PublicationInfo> element SHOULD only be used on the root element of a metadata document. |
||
| 84 | */ |
||
| 85 | $toplevel_pubInfo = array_values(array_filter($extensions->getList(), function ($ext) { |
||
| 86 | return $ext instanceof PublicationInfo; |
||
| 87 | })); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * When a <mdrpi:PublicationPath> element appears in the <md:Extensions> element of a |
||
| 91 | * <md:EntitiesDescriptor> element it applies to all descendant <md:EntitiesDescriptor> and |
||
| 92 | * <md:EntityDescriptor> elements. That is to say, this is equivalent to putting an identical |
||
| 93 | * <mdrpi:PublicationPath> on every descendant <md:EntitiesDescriptor> and <md:EntityDescriptor>. |
||
| 94 | * When used in this manner, descendant <md:EntitiesDescriptor> and <md:EntityDescriptor> |
||
| 95 | * elements MUST NOT contain a <mdrpi:PublicationPath> element in their <md:Extensions> element. |
||
| 96 | */ |
||
| 97 | $toplevel_pubPath = array_values(array_filter($extensions->getList(), function ($ext) { |
||
| 98 | return $ext instanceof PublicationPath; |
||
| 99 | })); |
||
| 100 | |||
| 101 | if (count($toplevel_regInfo) > 0 || count($toplevel_pubInfo) > 0 || count($toplevel_pubPath)) { |
||
| 102 | $nestedExtensions = []; |
||
| 103 | foreach (array_merge($entityDescriptors, $entitiesDescriptors) as $ed) { |
||
| 104 | $nestedExtensions = array_merge($nestedExtensions, $this->getRecursiveExtensions($ed)); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (count($toplevel_regInfo) > 0) { |
||
| 108 | $nested_regInfo = array_values(array_filter($nestedExtensions, function ($ext) { |
||
| 109 | return $ext instanceof RegistrationInfo; |
||
| 110 | })); |
||
| 111 | |||
| 112 | Assert::count( |
||
| 113 | $nested_regInfo, |
||
| 114 | 0, |
||
| 115 | "<mdrpi:RegistrationInfo> already set at top-level.", |
||
| 116 | ProtocolViolationException::class, |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | if (count($toplevel_pubInfo) > 0) { |
||
| 121 | $nested_pubInfo = array_values(array_filter($nestedExtensions, function ($ext) { |
||
| 122 | return $ext instanceof PublicationInfo; |
||
| 123 | })); |
||
| 124 | |||
| 125 | Assert::count( |
||
| 126 | $nested_pubInfo, |
||
| 127 | 0, |
||
| 128 | "<mdrpi:PublicationInfo> already set at top-level.", |
||
| 129 | ProtocolViolationException::class, |
||
| 130 | ); |
||
| 131 | } |
||
| 132 | |||
| 133 | if (count($toplevel_pubPath) > 0) { |
||
| 134 | $nested_pubPath = array_values(array_filter($nestedExtensions, function ($ext) { |
||
| 135 | return $ext instanceof PublicationPath; |
||
| 136 | })); |
||
| 137 | |||
| 138 | Assert::count( |
||
| 139 | $nested_pubPath, |
||
| 140 | 0, |
||
| 141 | "<mdrpi:PublicationPath> already set at top-level.", |
||
| 142 | ProtocolViolationException::class, |
||
| 143 | ); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | parent::__construct($ID, $validUntil, $cacheDuration, $extensions); |
||
| 149 | } |
||
| 290 |