| Conditions | 13 | 
| Paths | 64 | 
| Total Lines | 114 | 
| Code Lines | 70 | 
| Lines | 8 | 
| Ratio | 7.02 % | 
| 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  | 
            ||
| 159 | public function importPriceInfo(  | 
            ||
| 160 | \CultureFeed_Cdb_Data_DetailList $details,  | 
            ||
| 161 | $jsonLD  | 
            ||
| 162 |     ) { | 
            ||
| 163 | $mainLanguage = $this->getMainLanguage($jsonLD);  | 
            ||
| 164 | |||
| 165 | $detailsArray = [];  | 
            ||
| 166 |         foreach ($details as $detail) { | 
            ||
| 167 | $detailsArray[] = $detail;  | 
            ||
| 168 | }  | 
            ||
| 169 | $details = $detailsArray;  | 
            ||
| 170 | |||
| 171 | $mainLanguageDetails = array_filter(  | 
            ||
| 172 | $details,  | 
            ||
| 173 |             function (\CultureFeed_Cdb_Data_Detail $detail) use ($mainLanguage) { | 
            ||
| 174 | return $detail->getLanguage() === $mainLanguage->getCode();  | 
            ||
| 175 | }  | 
            ||
| 176 | );  | 
            ||
| 177 | |||
| 178 | /* @var \CultureFeed_Cdb_Data_EventDetail $mainLanguageDetail */  | 
            ||
| 179 | $mainLanguageDetail = reset($mainLanguageDetails);  | 
            ||
| 180 |         if (!$mainLanguageDetail) { | 
            ||
| 181 | return;  | 
            ||
| 182 | }  | 
            ||
| 183 | |||
| 184 | $mainLanguagePrice = $mainLanguageDetail->getPrice();  | 
            ||
| 185 | |||
| 186 |         if (!$mainLanguagePrice) { | 
            ||
| 187 | return;  | 
            ||
| 188 | }  | 
            ||
| 189 | |||
| 190 | $basePrice = $mainLanguagePrice->getValue();  | 
            ||
| 191 |         if ($basePrice !== null) { | 
            ||
| 192 | $basePrice = floatval($basePrice);  | 
            ||
| 193 | }  | 
            ||
| 194 | |||
| 195 |         if (!$basePrice) { | 
            ||
| 196 | return;  | 
            ||
| 197 | }  | 
            ||
| 198 | |||
| 199 | $basePrice = new BasePrice(  | 
            ||
| 200 | Price::fromFloat($basePrice),  | 
            ||
| 201 |             Currency::fromNative('EUR') | 
            ||
| 202 | );  | 
            ||
| 203 | |||
| 204 | /* @var Tariff[] $tariffs */  | 
            ||
| 205 | $tariffs = [];  | 
            ||
| 206 |         foreach ($details as $detail) { | 
            ||
| 207 | $language = null;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 208 | $price = null;  | 
            ||
| 209 | $description = null;  | 
            ||
| 210 | |||
| 211 | $language = $detail->getLanguage();  | 
            ||
| 212 | |||
| 213 | $price = $detail->getPrice();  | 
            ||
| 214 |             if (!$price) { | 
            ||
| 215 | continue;  | 
            ||
| 216 | }  | 
            ||
| 217 | |||
| 218 | $description = $price->getDescription();  | 
            ||
| 219 |             if (!$description) { | 
            ||
| 220 | continue;  | 
            ||
| 221 | }  | 
            ||
| 222 | |||
| 223 | $translatedTariffs = $this->priceDescriptionParser->parse($description);  | 
            ||
| 224 |             if (empty($translatedTariffs)) { | 
            ||
| 225 | continue;  | 
            ||
| 226 | }  | 
            ||
| 227 | |||
| 228 | // Skip the base price.  | 
            ||
| 229 | array_shift($translatedTariffs);  | 
            ||
| 230 | |||
| 231 | $tariffIndex = 0;  | 
            ||
| 232 |             foreach ($translatedTariffs as $tariffName => $tariffPrice) { | 
            ||
| 233 |                 if (!isset($tariffs[$tariffIndex])) { | 
            ||
| 234 | $tariff = new Tariff(  | 
            ||
| 235 | new MultilingualString(new Language($language), new StringLiteral($tariffName)),  | 
            ||
| 236 | Price::fromFloat($tariffPrice),  | 
            ||
| 237 |                         Currency::fromNative('EUR') | 
            ||
| 238 | );  | 
            ||
| 239 |                 } else { | 
            ||
| 240 | $tariff = $tariffs[$tariffIndex];  | 
            ||
| 241 | $name = $tariff->getName();  | 
            ||
| 242 | $name = $name->withTranslation(new Language($language), new StringLiteral($tariffName));  | 
            ||
| 243 | $tariff = new Tariff(  | 
            ||
| 244 | $name,  | 
            ||
| 245 | $tariff->getPrice(),  | 
            ||
| 246 | $tariff->getCurrency()  | 
            ||
| 247 | );  | 
            ||
| 248 | }  | 
            ||
| 249 | |||
| 250 | $tariffs[$tariffIndex] = $tariff;  | 
            ||
| 251 | $tariffIndex++;  | 
            ||
| 252 | }  | 
            ||
| 253 | }  | 
            ||
| 254 | |||
| 255 | $jsonLD->priceInfo = [  | 
            ||
| 256 | [  | 
            ||
| 257 | 'category' => 'base',  | 
            ||
| 258 | 'name' => $this->basePriceTranslations,  | 
            ||
| 259 | 'price' => $basePrice->getPrice()->toFloat(),  | 
            ||
| 260 | 'priceCurrency' => $basePrice->getCurrency()->getCode()->toNative(),  | 
            ||
| 261 | ],  | 
            ||
| 262 | ];  | 
            ||
| 263 | |||
| 264 | View Code Duplication |         foreach ($tariffs as $tariff) { | 
            |
| 265 | $jsonLD->priceInfo[] = [  | 
            ||
| 266 | 'category' => 'tariff',  | 
            ||
| 267 | 'name' => $tariff->getName()->serialize(),  | 
            ||
| 268 | 'price' => $tariff->getPrice()->toFloat(),  | 
            ||
| 269 | 'priceCurrency' => $tariff->getCurrency()->getCode()->toNative(),  | 
            ||
| 270 | ];  | 
            ||
| 271 | }  | 
            ||
| 272 | }  | 
            ||
| 273 | }  | 
            ||
| 274 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.