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