| Conditions | 13 | 
| Paths | 24 | 
| Total Lines | 72 | 
| 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 | ||
| 85 | 	private function findText( DIWikiPage $subject, Title $target, string $caption, string $languageCode ) : string { | ||
| 86 | |||
| 87 | $requestOptions = new RequestOptions(); | ||
| 88 | $requestOptions->setCaller( __METHOD__ ); | ||
| 89 | |||
| 90 | $dataItems = $this->store->getPropertyValues( | ||
| 91 | $subject, | ||
| 92 | new DIProperty( '_INST' ), | ||
| 93 | $requestOptions | ||
| 94 | ); | ||
| 95 | |||
| 96 | $categories = []; | ||
| 97 | |||
| 98 | 		foreach ( $dataItems as $dataItem ) { | ||
| 99 | $categories[] = $dataItem->getDBKey(); | ||
| 100 | } | ||
| 101 | |||
| 102 | $this->rule = $this->ruleFinder->findRule( $categories ); | ||
| 103 | |||
| 104 | 		if ( $this->rule->isEmpty() ) { | ||
| 105 | return ''; | ||
| 106 | } | ||
| 107 | |||
| 108 | 		if ( $caption !== '' && !$this->get( 'allow_caption_override', false ) ) { | ||
| 109 | return ''; | ||
| 110 | } | ||
| 111 | |||
| 112 | 		if ( ( $property = $this->get( 'caption_property', '' ) ) === '' ) { | ||
| 113 | return ''; | ||
| 114 | } | ||
| 115 | |||
| 116 | $property = DIProperty::newFromUserLabel( $property ); | ||
| 117 | |||
| 118 | $text = ''; | ||
| 119 | $maxLength = $this->get( 'max_length', 200 ); | ||
| 120 | |||
| 121 | 		if ( $property->findPropertyValueType() === MonolingualTextValue::TYPE_ID ) { | ||
| 122 | $text .= $this->fetchTextByLanguageCode( $subject, $property, $languageCode ); | ||
| 123 | 		} else { | ||
| 124 | $dataItems = $this->store->getPropertyValues( | ||
| 125 | $subject, | ||
| 126 | $property, | ||
| 127 | $requestOptions | ||
| 128 | ); | ||
| 129 | |||
| 130 | 			if ( $dataItems === [] ) { | ||
| 131 | return ''; | ||
| 132 | } | ||
| 133 | |||
| 134 | 			foreach ( $dataItems as $dataItem ) { | ||
| 135 | |||
| 136 | 				if ( !$dataItem instanceof DIBlob ) { | ||
| 137 | continue; | ||
| 138 | } | ||
| 139 | |||
| 140 | $text .= $dataItem->getString(); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | $length = mb_strlen( $text ); | ||
| 145 | |||
| 146 | // Reduces the length and finish it with a whole word | ||
| 147 | 		if ( $maxLength > 0 && $length >= $maxLength ) { | ||
| 148 | $text = Normalizer::reduceLengthTo( $text, $maxLength ) . ' …'; | ||
| 149 | } | ||
| 150 | |||
| 151 | 		if ( $this->get( 'add_figures_reference', false ) ) { | ||
| 152 | $text = wfMessage( 'semantic-imagecaption-figures', $target->semanticimagecaptioncount )->parse() . " $text"; | ||
| 153 | } | ||
| 154 | |||
| 155 | return $text; | ||
| 156 | } | ||
| 157 | |||
| 203 |