| Conditions | 12 |
| Paths | 282 |
| Total Lines | 77 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | function getRawHtmlWithAgeVerification($url, $cookie = false, $postData = null) |
||
| 24 | { |
||
| 25 | static $ageVerificationManager = null; |
||
| 26 | |||
| 27 | // Initialize manager on first use |
||
| 28 | if ($ageVerificationManager === null) { |
||
| 29 | $ageVerificationManager = new AgeVerificationManager; |
||
| 30 | } |
||
| 31 | |||
| 32 | // Check if this is an adult site that needs age verification |
||
| 33 | $adultSites = [ |
||
| 34 | 'adultdvdempire.com', |
||
| 35 | 'adultdvdmarketplace.com', |
||
| 36 | 'aebn.net', |
||
| 37 | 'hotmovies.com', |
||
| 38 | 'popporn.com', |
||
| 39 | ]; |
||
| 40 | |||
| 41 | $isAdultSite = false; |
||
| 42 | foreach ($adultSites as $site) { |
||
| 43 | if (stripos($url, $site) !== false) { |
||
| 44 | $isAdultSite = true; |
||
| 45 | break; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | // For adult sites, use the age verification manager |
||
| 50 | if ($isAdultSite) { |
||
| 51 | try { |
||
| 52 | $options = []; |
||
| 53 | |||
| 54 | // Handle POST data if provided |
||
| 55 | if ($postData !== null) { |
||
| 56 | $options['form_params'] = $postData; |
||
| 57 | $cookieJar = $ageVerificationManager->getCookieJar($url); |
||
| 58 | |||
| 59 | $client = new Client([ |
||
| 60 | 'cookies' => $cookieJar, |
||
| 61 | 'headers' => [ |
||
| 62 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', |
||
| 63 | 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
||
| 64 | ], |
||
| 65 | ]); |
||
| 66 | |||
| 67 | $response = $client->post($url, $options); |
||
| 68 | $html = $response->getBody()->getContents(); |
||
| 69 | } else { |
||
| 70 | $html = $ageVerificationManager->makeRequest($url, $options); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Try to decode as JSON (some APIs return JSON) |
||
| 74 | if ($html !== false) { |
||
| 75 | $jsonResponse = json_decode($html, true); |
||
| 76 | if (json_last_error() === JSON_ERROR_NONE) { |
||
| 77 | return $jsonResponse; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | return $html; |
||
| 82 | |||
| 83 | } catch (RequestException $e) { |
||
| 84 | if (config('app.debug') === true) { |
||
| 85 | \Log::error('getRawHtmlWithAgeVerification: '.$e->getMessage()); |
||
| 86 | } |
||
| 87 | |||
| 88 | return false; |
||
| 89 | } catch (\Exception $e) { |
||
| 90 | if (config('app.debug') === true) { |
||
| 91 | \Log::error('getRawHtmlWithAgeVerification: '.$e->getMessage()); |
||
| 92 | } |
||
| 93 | |||
| 94 | return false; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // For non-adult sites, use standard approach |
||
| 99 | return getRawHtml($url, $cookie, $postData); |
||
| 100 | } |
||
| 186 |