AppMarket   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchAppDetails() 0 17 3
B mobileAppStore() 0 24 5
1
<?php
2
3
namespace SurajAdsul\AppMarket;
4
5
class AppMarket
6
{
7
    const ANDROID_SUBSTRING = '://play.google.com';
8
    const IOS_REGEX = '/https?:\/\/itunes\.apple\.com\/((?<country>[a-zA-Z]{2})\/)?.+\/id(?<id>\d+)/';
9
    const PLATFORM_ANDROID = 1;
10
    const PLATFORM_IOS = 2;
11
12
    public function fetchAppDetails($previewUrl)
13
    {
14
        $details = $this->mobileAppStore($previewUrl);
15
16
        switch ($details['platform']) {
17
            case self::PLATFORM_IOS:
18
                $appDetails = new AppStoreInfo($details);
19
                break;
20
            case self::PLATFORM_ANDROID:
21
                $appDetails = new PlayStoreInfo($details);
22
                break;
23
            default:
24
                throw new \Exception();
25
        }
26
27
        return $appDetails;
28
    }
29
30
    private function mobileAppStore($previewUrl, $withCountry = false)
0 ignored issues
show
Unused Code introduced by
The parameter $withCountry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        $storeId = null;
33
        $platform = null;
34
        $country = null;
0 ignored issues
show
Unused Code introduced by
$country is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
        $matches = [];
36
37
        if (strpos($previewUrl, self::ANDROID_SUBSTRING) !== false) {
38
            $request = new \GuzzleHttp\Psr7\Request('GET', $previewUrl);
39
            parse_str($request->getUri()->getQuery(), $output);
40
            $storeId = $output['id'] ?: null;
41
            $platform = self::PLATFORM_ANDROID;
42
        } elseif (preg_match(self::IOS_REGEX, $previewUrl, $matches)) {
43
            $storeId = ! empty($matches['id']) ? $matches['id'] : null;
44
            $platform = self::PLATFORM_IOS;
45
        }
46
47
        $data = [
48
            'storeId' => $storeId,
49
            'platform' => $platform,
50
        ];
51
52
        return $data;
53
    }
54
}
55