| Conditions | 12 | 
| Paths | 17 | 
| Total Lines | 41 | 
| Code Lines | 25 | 
| 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 | ||
| 33 | 	public function validate( $value, $alldata ) { | ||
| 34 | 		if ( $this->mParent->getMethod() === 'get' && $value === '' ) { | ||
| 35 | // If the form is a GET form and has no value, assume it hasn't been | ||
| 36 | // submitted yet, and skip validation | ||
| 37 | return parent::validate( $value, $alldata ); | ||
| 38 | } | ||
| 39 | 		try { | ||
| 40 | 			if ( !$this->mParams['relative'] ) { | ||
| 41 | $title = Title::newFromTextThrow( $value ); | ||
| 42 | 			} else { | ||
| 43 | // Can't use Title::makeTitleSafe(), because it doesn't throw useful exceptions | ||
| 44 | global $wgContLang; | ||
| 45 | $namespaceName = $wgContLang->getNsText( $this->mParams['namespace'] ); | ||
| 46 | $title = Title::newFromTextThrow( $namespaceName . ':' . $value ); | ||
| 47 | } | ||
| 48 | 		} catch ( MalformedTitleException $e ) { | ||
| 49 | $msg = $this->msg( $e->getErrorMessage() ); | ||
| 50 | $params = $e->getErrorMessageParameters(); | ||
| 51 | 			if ( $params ) { | ||
| 52 | $msg->params( $params ); | ||
| 53 | } | ||
| 54 | return $msg->parse(); | ||
| 55 | } | ||
| 56 | |||
| 57 | $text = $title->getPrefixedText(); | ||
| 58 | if ( $this->mParams['namespace'] !== false && | ||
| 59 | !$title->inNamespace( $this->mParams['namespace'] ) | ||
| 60 | 		) { | ||
| 61 | return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text )->parse(); | ||
| 62 | } | ||
| 63 | |||
| 64 | 		if ( $this->mParams['creatable'] && !$title->canExist() ) { | ||
| 65 | return $this->msg( 'htmlform-title-not-creatable', $text )->escaped(); | ||
| 66 | } | ||
| 67 | |||
| 68 | 		if ( $this->mParams['exists'] && !$title->exists() ) { | ||
| 69 | return $this->msg( 'htmlform-title-not-exists', $text )->parse(); | ||
| 70 | } | ||
| 71 | |||
| 72 | return parent::validate( $value, $alldata ); | ||
| 73 | } | ||
| 74 | |||
| 104 |