1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @author Ne-Lexa |
6
|
|
|
* @license MIT |
7
|
|
|
* @link https://github.com/Ne-Lexa/google-play-scraper |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Nelexa\GPlay\Model; |
11
|
|
|
|
12
|
|
|
use Nelexa\GPlay\Model\Builder\AppBuilder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Contains basic information about the application from the Google Play store. |
16
|
|
|
* |
17
|
|
|
* Some sections, such as search, similar applications, applications categories, etc. display |
18
|
|
|
* a list of applications with limited data. To get detailed information about the application, |
19
|
|
|
* you must call the appropriate method in the class {@see \Nelexa\GPlay\GPlayApps}. |
20
|
|
|
* |
21
|
|
|
* @see \Nelexa\GPlay\Model\AppId Application ID, application locale and country. |
22
|
|
|
* @see \Nelexa\GPlay\GPlayApps::search() Returns a list of applications from the Google Play |
23
|
|
|
* store for a search query. |
24
|
|
|
* @see \Nelexa\GPlay\GPlayApps::getSimilarApps() Returns a list of similar applications in |
25
|
|
|
* the Google Play store. |
26
|
|
|
* @see \Nelexa\GPlay\GPlayApps::getDeveloperApps() Returns a list of developer applications |
27
|
|
|
* in the Google Play store. |
28
|
|
|
* @see \Nelexa\GPlay\GPlayApps::getAppsByCategory() Returns a list of applications with basic |
29
|
|
|
* information from the category and collection of the Google Play store. |
30
|
|
|
*/ |
31
|
|
|
class App extends AppId implements \JsonSerializable |
32
|
|
|
{ |
33
|
|
|
use JsonSerializableTrait; |
34
|
|
|
|
35
|
|
|
/** @var string Application name. */ |
36
|
|
|
private $name; |
37
|
|
|
|
38
|
|
|
/** @var string|null Application summary. */ |
39
|
|
|
private $summary; |
40
|
|
|
|
41
|
|
|
/** @var Developer Application developer. */ |
42
|
|
|
private $developer; |
43
|
|
|
|
44
|
|
|
/** @var GoogleImage Application icon. */ |
45
|
|
|
private $icon; |
46
|
|
|
|
47
|
|
|
/** @var float Application rating on a five-point scale. */ |
48
|
|
|
private $score; |
49
|
|
|
|
50
|
|
|
/** @var string|null Price of the application or null if it is free. */ |
51
|
|
|
private $priceText; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Creates an object containing basic information about the Android application. |
55
|
|
|
* |
56
|
|
|
* @param AppBuilder $builder Application builder. |
57
|
|
|
* |
58
|
|
|
* @throws \InvalidArgumentException If not enough required data in the builder. |
59
|
|
|
* |
60
|
|
|
* @ignore |
61
|
|
|
*/ |
62
|
13 |
|
public function __construct(AppBuilder $builder) |
63
|
|
|
{ |
64
|
13 |
|
if (empty($builder->getId())) { |
65
|
1 |
|
throw new \InvalidArgumentException('Application ID cannot be null or empty. Solution: $appBuilder->setId(...);'); |
66
|
|
|
} |
67
|
13 |
|
if (empty($builder->getLocale())) { |
68
|
1 |
|
throw new \InvalidArgumentException('Locale cannot be null or empty. Solution: $appBuilder->setLocale(...);'); |
69
|
|
|
} |
70
|
13 |
|
if (empty($builder->getCountry())) { |
71
|
1 |
|
throw new \InvalidArgumentException('Country cannot be null or empty. Solution: $appBuilder->setCountry(...);'); |
72
|
|
|
} |
73
|
13 |
|
if (empty($builder->getName())) { |
74
|
1 |
|
throw new \InvalidArgumentException('The application name cannot be null or empty. Solution: $appBuilder->setName(...);'); |
75
|
|
|
} |
76
|
13 |
|
if ($builder->getDeveloper() === null) { |
77
|
1 |
|
throw new \InvalidArgumentException('Application developer cannot be null. Solution: $appBuilder->setDeveloper(...);'); |
78
|
|
|
} |
79
|
13 |
|
if ($builder->getIcon() === null) { |
80
|
1 |
|
throw new \InvalidArgumentException('Application icon cannot be null. Solution: $appBuilder->setIcon(...);'); |
81
|
|
|
} |
82
|
|
|
|
83
|
13 |
|
parent::__construct( |
84
|
13 |
|
$builder->getId(), |
85
|
13 |
|
$builder->getLocale(), |
86
|
13 |
|
$builder->getCountry() |
87
|
|
|
); |
88
|
|
|
|
89
|
13 |
|
$this->name = $builder->getName(); |
90
|
13 |
|
$this->summary = $builder->getSummary(); |
91
|
13 |
|
$this->developer = $builder->getDeveloper(); |
92
|
13 |
|
$this->icon = $builder->getIcon(); |
93
|
13 |
|
$this->score = $builder->getScore(); |
94
|
13 |
|
$this->priceText = $builder->getPriceText(); |
95
|
13 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns application name. |
99
|
|
|
* |
100
|
|
|
* @return string Application name. |
101
|
|
|
*/ |
102
|
3 |
|
public function getName(): string |
103
|
|
|
{ |
104
|
3 |
|
return $this->name; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns application summary. |
109
|
|
|
* |
110
|
|
|
* @return string|null Application summary. |
111
|
|
|
*/ |
112
|
1 |
|
public function getSummary(): ?string |
113
|
|
|
{ |
114
|
1 |
|
return $this->summary; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns application developer |
119
|
|
|
* |
120
|
|
|
* @return Developer Application developer. |
121
|
|
|
*/ |
122
|
3 |
|
public function getDeveloper(): Developer |
123
|
|
|
{ |
124
|
3 |
|
return $this->developer; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns application icon. |
129
|
|
|
* |
130
|
|
|
* @return GoogleImage Application icon. |
131
|
|
|
*/ |
132
|
4 |
|
public function getIcon(): GoogleImage |
133
|
|
|
{ |
134
|
4 |
|
return $this->icon; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns application rating on a five-point scale. |
139
|
|
|
* |
140
|
|
|
* @return float Rating application. |
141
|
|
|
*/ |
142
|
1 |
|
public function getScore(): float |
143
|
|
|
{ |
144
|
1 |
|
return $this->score; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns the price of the application. |
149
|
|
|
* |
150
|
|
|
* @return string|null Application price or null if it is free. |
151
|
|
|
*/ |
152
|
1 |
|
public function getPriceText(): ?string |
153
|
|
|
{ |
154
|
1 |
|
return $this->priceText; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Checks that this application is free. |
159
|
|
|
* |
160
|
|
|
* @return bool `true` if the application is free and `false` if paid. |
161
|
|
|
*/ |
162
|
1 |
|
public function isFree(): bool |
163
|
|
|
{ |
164
|
1 |
|
return $this->priceText === null; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Creates a new application builder. |
169
|
|
|
* |
170
|
|
|
* @return AppBuilder Application builder. |
171
|
|
|
* @ignore |
172
|
|
|
*/ |
173
|
13 |
|
public static function newBuilder(): AppBuilder |
174
|
|
|
{ |
175
|
13 |
|
return new AppBuilder(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Returns class properties as an array. |
180
|
|
|
* |
181
|
|
|
* @return array Class properties as an array. |
182
|
|
|
*/ |
183
|
|
|
public function asArray(): array |
184
|
|
|
{ |
185
|
|
|
return [ |
186
|
|
|
'id' => $this->getId(), |
187
|
|
|
'url' => $this->getUrl(), |
188
|
|
|
'locale' => $this->getLocale(), |
189
|
|
|
'country' => $this->getCountry(), |
190
|
|
|
'name' => $this->name, |
191
|
|
|
'summary' => $this->summary, |
192
|
|
|
'developer' => $this->developer->asArray(), |
193
|
|
|
'icon' => $this->icon->getUrl(), |
194
|
|
|
'score' => $this->score, |
195
|
|
|
'priceText' => $this->priceText, |
196
|
|
|
]; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|