AppId   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 85%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 96
ccs 17
cts 20
cp 0.85
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A __construct() 0 11 2
A getLocale() 0 3 1
A getCountry() 0 3 1
A getFullUrl() 0 7 1
A getUrl() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (c) Ne-Lexa
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 *
11
 * @see https://github.com/Ne-Lexa/google-play-scraper
12
 */
13
14
namespace Nelexa\GPlay\Model;
15
16
use Nelexa\GPlay\GPlayApps;
17
use Nelexa\GPlay\Util\LocaleHelper;
18
19
/**
20
 * Contains the application ID, as well as the locale and country for which the information was or will be obtained.
21
 *
22
 * This class is the base class for {@see App} and {@see AppInfo}.
23
 *
24
 * @see App Contains basic information about the application
25
 *     from the Google Play store.
26
 * @see AppInfo Contains detailed information about the
27
 *     application from the Google Play store.
28
 */
29
class AppId
30
{
31
    /** @var string Application ID (Android package name) */
32
    private $id;
33
34
    /** @var string Locale (site language) */
35
    private $locale;
36
37
    /**
38
     * @var string the country of the request for information about the
39
     *             application (affects the price and currency of paid applications
40
     *             and possibly their availability on the Google Play store)
41
     */
42
    private $country;
43
44
    /**
45
     * Creates an \Nelexa\GPlay\Model\AppId object.
46
     *
47
     * @param string $id      application ID (Android package name)
48
     * @param string $locale  Locale (ex. en_US, en-CA or en). Default is 'en_US'.
49
     * @param string $country Country (affects prices). Default is 'us'.
50
     */
51 44
    public function __construct(
52
        string $id,
53
        string $locale = GPlayApps::DEFAULT_LOCALE,
54
        string $country = GPlayApps::DEFAULT_COUNTRY
55
    ) {
56 44
        if (empty($id)) {
57 3
            throw new \InvalidArgumentException('Application ID cannot be empty');
58
        }
59 41
        $this->id = $id;
60 41
        $this->locale = LocaleHelper::getNormalizeLocale($locale);
61 41
        $this->country = $country;
62
    }
63
64
    /**
65
     * Returns the application ID (android package name).
66
     *
67
     * @return string application ID (android package name)
68
     */
69 12
    public function getId(): string
70
    {
71 12
        return $this->id;
72
    }
73
74
    /**
75
     * Returns the locale (site language) for which the information was received.
76
     *
77
     * @return string Locale (ex. en_US, en-CA or en). Default is 'en_US'.
78
     */
79 3
    public function getLocale(): string
80
    {
81 3
        return $this->locale;
82
    }
83
84
    /**
85
     * Returns the country of the request for information about the application.
86
     *
87
     * This parameter affects the price and currency of paid applications
88
     * and, possibly, the presence of an application in the Google Play store).
89
     *
90
     * @return string Country (affects prices). Default is 'us'.
91
     */
92 4
    public function getCountry(): string
93
    {
94 4
        return $this->country;
95
    }
96
97
    /**
98
     * Returns the URL of the application page in the Google Play store.
99
     *
100
     * @return string url of the app page in Google Play
101
     */
102
    public function getUrl(): string
103
    {
104
        return GPlayApps::GOOGLE_PLAY_APPS_URL . '/details?' . http_build_query(
105
            [
106
                GPlayApps::REQ_PARAM_ID => $this->id,
107
            ]
108
        );
109
    }
110
111
    /**
112
     * Returns the full URL of the app's page on Google Play, specifying
113
     * the locale and country of the request.
114
     *
115
     * @return string URL of the app's page on Google Play, specifying the
116
     *                locale and country of the request
117
     */
118 19
    public function getFullUrl(): string
119
    {
120 19
        return GPlayApps::GOOGLE_PLAY_APPS_URL . '/details?' . http_build_query(
121
            [
122 19
                GPlayApps::REQ_PARAM_ID => $this->id,
123 19
                GPlayApps::REQ_PARAM_LOCALE => $this->locale,
124 19
                GPlayApps::REQ_PARAM_COUNTRY => $this->country,
125
            ]
126
        );
127
    }
128
}
129