| Conditions | 29 | 
| Paths | > 20000 | 
| Total Lines | 177 | 
| Code Lines | 140 | 
| 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 __invoke(RequestInterface $request, ResponseInterface $response): AppDetail  | 
            ||
| 34 |     { | 
            ||
| 35 | $query = parse_query($request->getUri()->getQuery());  | 
            ||
| 36 | $appId = $query[GPlayApps::REQ_PARAM_APP_ID];  | 
            ||
| 37 | $locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE;  | 
            ||
| 38 | $url = GPlayApps::GOOGLE_PLAY_APPS_URL . '/details?' . http_build_query([  | 
            ||
| 39 | GPlayApps::REQ_PARAM_APP_ID => $appId,  | 
            ||
| 40 | ]);  | 
            ||
| 41 | |||
| 42 | $scriptData = ScraperUtil::extractScriptData($response->getBody()->getContents());  | 
            ||
| 43 | |||
| 44 | $scriptDataInfo = null;  | 
            ||
| 45 | $scriptDataRating = null;  | 
            ||
| 46 | $scriptDataPrice = null;  | 
            ||
| 47 | $scriptDataVersion = null;  | 
            ||
| 48 | $scriptDataReviews = [];  | 
            ||
| 49 | |||
| 50 |         foreach ($scriptData as $key => $scriptValue) { | 
            ||
| 51 |             if (isset($scriptValue[0][12][5][5][4][2])) { // ds:5 | 
            ||
| 52 | $scriptDataInfo = $scriptValue;  | 
            ||
| 53 |             } elseif (isset($scriptValue[0][2][0][0][0][1][0][0])) { // ds:3 | 
            ||
| 54 | $scriptDataPrice = $scriptValue;  | 
            ||
| 55 | } elseif (isset($scriptValue[0][0][0])  | 
            ||
| 56 | && is_string($scriptValue[0][0][0])  | 
            ||
| 57 |                 && strpos($scriptValue[0][0][0], 'gp:') === 0) { // ds:15 | 
            ||
| 58 | $scriptDataReviews = $scriptValue;  | 
            ||
| 59 |             } elseif (isset($scriptValue[0][6][3][1])) { // ds:7 | 
            ||
| 60 | $scriptDataRating = $scriptValue;  | 
            ||
| 61 | } elseif (isset($scriptValue[0])  | 
            ||
| 62 | && is_string($scriptValue[0])  | 
            ||
| 63 |                 && count($scriptValue) === 3) { // ds:8 | 
            ||
| 64 | $scriptDataVersion = $scriptValue;  | 
            ||
| 65 | }  | 
            ||
| 66 | }  | 
            ||
| 67 | |||
| 68 | if (  | 
            ||
| 69 | $scriptDataInfo === null ||  | 
            ||
| 70 | $scriptDataRating === null ||  | 
            ||
| 71 | $scriptDataPrice === null ||  | 
            ||
| 72 | $scriptDataVersion === null  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 73 |         ) { | 
            ||
| 74 |             throw (new GooglePlayException('Unable to get data for this application.'))->setUrl($url); | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 | $name = $scriptDataInfo[0][0][0];  | 
            ||
| 78 | $descriptionHTML = $scriptDataInfo[0][10][0][1];  | 
            ||
| 79 | $description = ScraperUtil::html2text($descriptionHTML);  | 
            ||
| 80 | |||
| 81 | $developer = $this->extractDeveloper($scriptDataInfo);  | 
            ||
| 82 | $category = $this->extractCategory($scriptDataInfo[0][12][13][0]);  | 
            ||
| 83 | |||
| 84 | $summary = empty($scriptDataInfo[0][10][1][1]) ?  | 
            ||
| 85 | null :  | 
            ||
| 86 | ScraperUtil::html2text($scriptDataInfo[0][10][1][1]);  | 
            ||
| 87 | |||
| 88 | $installs = $scriptDataInfo[0][12][9][2] ?? 0;  | 
            ||
| 89 | $score = (float)($scriptDataRating[0][6][0][1] ?? 0);  | 
            ||
| 90 | $numberVoters = (int)($scriptDataRating[0][6][2][1] ?? 0);  | 
            ||
| 91 | $reviewsCount = (int)($scriptDataRating[0][6][3][1] ?? 0);  | 
            ||
| 92 | $histogram = $scriptDataRating[0][6][1] ?? null;  | 
            ||
| 93 | |||
| 94 | $histogramRating = new HistogramRating(  | 
            ||
| 95 | $histogram[5][1] ?? 0,  | 
            ||
| 96 | $histogram[4][1] ?? 0,  | 
            ||
| 97 | $histogram[3][1] ?? 0,  | 
            ||
| 98 | $histogram[2][1] ?? 0,  | 
            ||
| 99 | $histogram[1][1] ?? 0  | 
            ||
| 100 | );  | 
            ||
| 101 | |||
| 102 | $price = isset($scriptDataPrice[0][2][0][0][0][1][0][0]) ?  | 
            ||
| 103 | (float)($scriptDataPrice[0][2][0][0][0][1][0][0] / 1000000) :  | 
            ||
| 104 | 0;  | 
            ||
| 105 | $currency = $scriptDataPrice[0][2][0][0][0][1][0][1];  | 
            ||
| 106 | $priceText = $scriptDataPrice[0][2][0][0][0][1][0][2] ?: 'Free';  | 
            ||
| 107 | $offersIAPCost = $scriptDataInfo[0][12][12][0] ?? null;  | 
            ||
| 108 | $adSupported = (bool)$scriptDataInfo[0][12][14][0];  | 
            ||
| 109 | |||
| 110 | [$size, $appVersion, $androidVersion] = $scriptDataVersion;  | 
            ||
| 111 |         if (LocaleHelper::isDependOnDevice($locale, $size)) { | 
            ||
| 112 | $size = null;  | 
            ||
| 113 | }  | 
            ||
| 114 |         if (LocaleHelper::isDependOnDevice($locale, $appVersion)) { | 
            ||
| 115 | $appVersion = null;  | 
            ||
| 116 | }  | 
            ||
| 117 |         if (LocaleHelper::isDependOnDevice($locale, $androidVersion)) { | 
            ||
| 118 | $androidVersion = null;  | 
            ||
| 119 | $minAndroidVersion = null;  | 
            ||
| 120 |         } else { | 
            ||
| 121 |             $minAndroidVersion = preg_replace('~.*?(\d+(\.\d+)?).*~', '$1', $androidVersion); | 
            ||
| 122 | }  | 
            ||
| 123 | |||
| 124 | $editorsChoice = !empty($scriptDataInfo[0][12][15][1][1]);  | 
            ||
| 125 | $privacyPoliceUrl = $scriptDataInfo[0][12][7][2];  | 
            ||
| 126 | |||
| 127 | $categoryFamily = $this->extractCategory($scriptDataInfo[0][12][13][1]??[]);  | 
            ||
| 128 | |||
| 129 | $icon = empty($scriptDataInfo[0][12][1][3][2]) ?  | 
            ||
| 130 | null :  | 
            ||
| 131 | new GoogleImage($scriptDataInfo[0][12][1][3][2]);  | 
            ||
| 132 | |||
| 133 | $headerImage = empty($scriptDataInfo[0][12][2][3][2]) ?  | 
            ||
| 134 | null :  | 
            ||
| 135 | new GoogleImage($scriptDataInfo[0][12][2][3][2]);  | 
            ||
| 136 | |||
| 137 | $screenshots = $this->extractScreenshots($scriptDataInfo);  | 
            ||
| 138 | $video = $this->extractVideo($scriptDataInfo);  | 
            ||
| 139 | |||
| 140 | $contentRating = $scriptDataInfo[0][12][4][0];  | 
            ||
| 141 | $released = null;  | 
            ||
| 142 |         if (isset($scriptDataInfo[0][12][36]) && $scriptDataInfo[0][12][36] !== null) { | 
            ||
| 143 | $released = DateStringFormatter::formatted($locale, $scriptDataInfo[0][12][36]);  | 
            ||
| 144 | }  | 
            ||
| 145 |         try { | 
            ||
| 146 | $updated = !empty($scriptDataInfo[0][12][8][0]) ?  | 
            ||
| 147 |                 new \DateTimeImmutable('@' . $scriptDataInfo[0][12][8][0]) | 
            ||
| 148 | : null;  | 
            ||
| 149 |         } catch (\Exception $e) { | 
            ||
| 150 | $updated = null;  | 
            ||
| 151 | }  | 
            ||
| 152 | |||
| 153 | $recentChanges = empty($scriptDataInfo[0][12][6][1]) ?  | 
            ||
| 154 | null :  | 
            ||
| 155 | ScraperUtil::html2text($scriptDataInfo[0][12][6][1]);  | 
            ||
| 156 | |||
| 157 | $translatedFromLanguage = null;  | 
            ||
| 158 | $translatedDescription = null;  | 
            ||
| 159 |         if (isset($scriptDataInfo[0][19][1])) { | 
            ||
| 160 | $translatedFromLanguage = LocaleHelper::findPreferredLanguage(  | 
            ||
| 161 | $locale,  | 
            ||
| 162 | $scriptDataInfo[0][19][1]  | 
            ||
| 163 | );  | 
            ||
| 164 | $translatedDescription = ScraperUtil::html2text($scriptDataInfo[0][19][0][0][1]);  | 
            ||
| 165 | }  | 
            ||
| 166 | |||
| 167 | $reviews = $this->extractReviews($url, $scriptDataReviews);  | 
            ||
| 168 | |||
| 169 | return new AppDetail(  | 
            ||
| 170 | AppDetail::newBuilder()  | 
            ||
| 171 | ->setId($appId)  | 
            ||
| 172 | ->setLocale($locale)  | 
            ||
| 173 | ->setName($name)  | 
            ||
| 174 | ->setDescription($description)  | 
            ||
| 175 | ->setTranslated($translatedDescription, $translatedFromLanguage)  | 
            ||
| 176 | ->setSummary($summary)  | 
            ||
| 177 | ->setIcon($icon)  | 
            ||
| 178 | ->setHeaderImage($headerImage)  | 
            ||
| 179 | ->setScreenshots($screenshots)  | 
            ||
| 180 | ->setDeveloper($developer)  | 
            ||
| 181 | ->setCategory($category)  | 
            ||
| 182 | ->setCategoryFamily($categoryFamily)  | 
            ||
| 183 | ->setVideo($video)  | 
            ||
| 184 | ->setRecentChanges($recentChanges)  | 
            ||
| 185 | ->setEditorsChoice($editorsChoice)  | 
            ||
| 186 | ->setPrivacyPoliceUrl($privacyPoliceUrl)  | 
            ||
| 187 | ->setInstalls($installs)  | 
            ||
| 188 | ->setScore($score)  | 
            ||
| 189 | ->setRecentChanges($recentChanges)  | 
            ||
| 190 | ->setEditorsChoice($editorsChoice)  | 
            ||
| 191 | ->setPrivacyPoliceUrl($privacyPoliceUrl)  | 
            ||
| 192 | ->setInstalls($installs)  | 
            ||
| 193 | ->setScore($score)  | 
            ||
| 194 | ->setNumberVoters($numberVoters)  | 
            ||
| 195 | ->setHistogramRating($histogramRating)  | 
            ||
| 196 | ->setPrice($price)  | 
            ||
| 197 | ->setCurrency($currency)  | 
            ||
| 198 | ->setPriceText($priceText)  | 
            ||
| 199 | ->setOffersIAPCost($offersIAPCost)  | 
            ||
| 200 | ->setAdSupported($adSupported)  | 
            ||
| 201 | ->setAppSize($size)  | 
            ||
| 202 | ->setAppVersion($appVersion)  | 
            ||
| 203 | ->setAndroidVersion($androidVersion)  | 
            ||
| 204 | ->setMinAndroidVersion($minAndroidVersion)  | 
            ||
| 205 | ->setContentRating($contentRating)  | 
            ||
| 206 | ->setReleased($released)  | 
            ||
| 207 | ->setUpdated($updated)  | 
            ||
| 208 | ->setReviewsCount($reviewsCount)  | 
            ||
| 209 | ->setReviews($reviews)  | 
            ||
| 210 | );  | 
            ||
| 340 |