Conditions | 11 |
Paths | 72 |
Total Lines | 35 |
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 |
||
134 | public function validate(): bool |
||
135 | { |
||
136 | $errorStorage = $this->getNode()->getZone()->getErrorsStore(); |
||
137 | |||
138 | if (!in_array($this->tag, [self::TAG_ISSUE, self::TAG_ISSUEWILD, self::TAG_IODEF])) { |
||
139 | $errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_TAG(), 'tag')); |
||
140 | } |
||
141 | |||
142 | if ($this->flags < 0 || $this->flags > 255) { |
||
143 | $errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_FLAGS(), 'flag')); |
||
144 | } |
||
145 | |||
146 | if (!Int16Validator::validate($this->getFlags())) { |
||
147 | $errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_INT16(), 'flags')); |
||
148 | } |
||
149 | |||
150 | if (in_array($this->getTag(), [self::TAG_ISSUEWILD, self::TAG_ISSUE]) && |
||
151 | $this->getValue() !== ';' |
||
152 | ) { |
||
153 | $parts = explode(";", $this->getValue()); |
||
154 | |||
155 | if (!preg_match(self::PATTERN_FQDN, $parts[0])) { |
||
156 | $errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_VALUE(), 'value')); |
||
157 | } |
||
158 | } |
||
159 | |||
160 | if ($this->getTag() == self::TAG_IODEF) { |
||
161 | if (!filter_var($this->getValue(), FILTER_VALIDATE_EMAIL) && !filter_var($this->getValue(), FILTER_VALIDATE_URL)) { |
||
162 | $errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_VALUE(), 'value')); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | /** @noinspection PhpInternalEntityUsedInspection */ |
||
167 | return parent::validate(); |
||
168 | } |
||
169 | |||
182 |