| Conditions | 7 |
| Paths | 9 |
| Total Lines | 101 |
| Code Lines | 57 |
| 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 |
||
| 96 | public function parse(XmlObject $xml): iterable |
||
| 97 | { |
||
| 98 | $donors = []; |
||
| 99 | |||
| 100 | foreach ($xml->getElements('/DocumentElement/MedgivandeViaHemsida') as $mandate) { |
||
| 101 | $orgNr = $mandate->readElement('/MedgivandeViaHemsida/Organisationsnr', new IdValidator); |
||
| 102 | |||
| 103 | if ($this->payeeOrgNr->format('S-sk') != $orgNr) { |
||
| 104 | throw new InvalidDataException(sprintf( |
||
| 105 | 'Invalid payee org nr %s, expecting %s', |
||
| 106 | $orgNr, |
||
| 107 | $this->payeeOrgNr->format('S-sk') |
||
| 108 | )); |
||
| 109 | } |
||
| 110 | |||
| 111 | $bankgiro = $mandate->readElement('/MedgivandeViaHemsida/Bankgironr', new AccountValidator); |
||
| 112 | |||
| 113 | if (preg_replace('/\D/', '', $this->payeeBankgiro->getNumber()) != preg_replace('/\D/', '', $bankgiro)) { |
||
| 114 | throw new InvalidDataException(sprintf( |
||
| 115 | 'Invalid payee bankgiro %s, expecting %s', |
||
| 116 | $bankgiro, |
||
| 117 | $this->payeeBankgiro->getNumber() |
||
| 118 | )); |
||
| 119 | } |
||
| 120 | |||
| 121 | $stringValidator = new StringValidator; |
||
| 122 | |||
| 123 | // require this empty element to exist |
||
| 124 | $mandate->readElement( |
||
| 125 | '/MedgivandeViaHemsida/Autogiroanmälan_x002C__x0020_medgivande', |
||
| 126 | $stringValidator |
||
| 127 | ); |
||
| 128 | |||
| 129 | $this->donorBuilder->reset(); |
||
| 130 | |||
| 131 | $this->donorBuilder->setMandateSource(MandateSources::MANDATE_SOURCE_ONLINE_FORM); |
||
| 132 | |||
| 133 | $this->donorBuilder->setName( |
||
| 134 | $mandate->readElement('/MedgivandeViaHemsida/Betalares_x0020_namn', $stringValidator) |
||
| 135 | ); |
||
| 136 | |||
| 137 | $this->donorBuilder->setPostalAddress( |
||
| 138 | new PostalAddress( |
||
| 139 | $mandate->readElement('/MedgivandeViaHemsida/Betalares_x0020_adress_1', $stringValidator), |
||
| 140 | $mandate->readElement('/MedgivandeViaHemsida/Betalares_x0020_adress_2', $stringValidator), |
||
| 141 | $mandate->readElement('/MedgivandeViaHemsida/Betalares_x0020_adress_3', $stringValidator), |
||
| 142 | $mandate->readElement('/MedgivandeViaHemsida/Betalares_x0020_postnr', new PostalCodeValidator), |
||
| 143 | $mandate->readElement('/MedgivandeViaHemsida/Betalares_x0020_postort', $stringValidator) |
||
| 144 | ) |
||
| 145 | ); |
||
| 146 | |||
| 147 | if ($mandate->hasElement('/MedgivandeViaHemsida/Betalarnummer')) { |
||
| 148 | try { |
||
| 149 | $this->donorBuilder->setPayerNumber( |
||
| 150 | $mandate->readElement('/MedgivandeViaHemsida/Betalarnummer', new PayerNumberValidator) |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | catch(ValidatorException $e) { |
||
|
|
|||
| 154 | $this->donorBuilder->setPayerNumber( |
||
| 155 | $mandate->readElement('/MedgivandeViaHemsida/Kontoinnehavarens_x0020_personnr', new IdValidator) |
||
| 156 | ); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->donorBuilder->setAccount( |
||
| 161 | $this->accountFactory->createAccount( |
||
| 162 | $mandate->readElement('/MedgivandeViaHemsida/Kontonr', new AccountValidator) |
||
| 163 | ) |
||
| 164 | ); |
||
| 165 | |||
| 166 | $this->donorBuilder->setId( |
||
| 167 | $this->idFactory->createId( |
||
| 168 | $mandate->readElement('/MedgivandeViaHemsida/Kontoinnehavarens_x0020_personnr', new IdValidator) |
||
| 169 | ) |
||
| 170 | ); |
||
| 171 | |||
| 172 | $this->donorBuilder->setAttribute( |
||
| 173 | 'verification_time', |
||
| 174 | $mandate->readElement('/MedgivandeViaHemsida/Verifieringstid', $stringValidator) |
||
| 175 | ); |
||
| 176 | |||
| 177 | $this->donorBuilder->setAttribute( |
||
| 178 | 'verification_code', |
||
| 179 | $mandate->readElement('/MedgivandeViaHemsida/Verifieringsreferens', $stringValidator) |
||
| 180 | ); |
||
| 181 | |||
| 182 | $formId = $mandate->readElement('/MedgivandeViaHemsida/Formulärnamn', $stringValidator); |
||
| 183 | |||
| 184 | foreach ($mandate->getElements('/MedgivandeViaHemsida/Övrig_x0020_info/customdata') as $custom) { |
||
| 185 | $this->translator->writeValue( |
||
| 186 | $this->donorBuilder, |
||
| 187 | $formId, |
||
| 188 | $custom->readElement('/customdata/name', $stringValidator), |
||
| 189 | $custom->readElement('/customdata/value', $stringValidator) |
||
| 190 | ); |
||
| 191 | } |
||
| 192 | |||
| 193 | $donors[] = $this->donorBuilder->buildDonor(); |
||
| 194 | } |
||
| 195 | |||
| 196 | return $donors; |
||
| 197 | } |
||
| 199 |
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