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\Model\Builder\DeveloperBuilder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Contains data on the application developer in the Google Play store. |
21
|
|
|
* |
22
|
|
|
* @see GPlayApps::getDeveloperInfo() Returns information about the |
23
|
|
|
* developer: name, icon, cover, description and website address. |
24
|
|
|
* @see GPlayApps::getDeveloperInfoForLocales() Returns information |
25
|
|
|
* about the developer for the locale array. |
26
|
|
|
* @see GPlayApps::getAppInfo() Returns detailed information about the |
27
|
|
|
* Android application from the Google Play store. |
28
|
|
|
* @see GPlayApps::getAppsInfo() Returns detailed information about |
29
|
|
|
* many android packages. |
30
|
|
|
* @see GPlayApps::getAppInLocales() Returns detailed information |
31
|
|
|
* about an application from the Google Play store for an array of locales. |
32
|
|
|
* @see GPlayApps::getAppInfoForAvailableLocales() Returns detailed |
33
|
|
|
* information about the application in all available locales. |
34
|
|
|
*/ |
35
|
|
|
class Developer implements \JsonSerializable |
36
|
|
|
{ |
37
|
|
|
use JsonSerializableTrait; |
38
|
|
|
|
39
|
|
|
/** @var string Developer id */ |
40
|
|
|
private $id; |
41
|
|
|
|
42
|
|
|
/** @var string url Developer page url in Google Play store */ |
43
|
|
|
private $url; |
44
|
|
|
|
45
|
|
|
/** @var string Developer name */ |
46
|
|
|
private $name; |
47
|
|
|
|
48
|
|
|
/** @var string|null Description of the developer */ |
49
|
|
|
private $description; |
50
|
|
|
|
51
|
|
|
/** @var string|null Developer website */ |
52
|
|
|
private $website; |
53
|
|
|
|
54
|
|
|
/** @var GoogleImage|null Developer icon */ |
55
|
|
|
private $icon; |
56
|
|
|
|
57
|
|
|
/** @var GoogleImage|null Developer cover */ |
58
|
|
|
private $cover; |
59
|
|
|
|
60
|
|
|
/** @var string|null Developer email */ |
61
|
|
|
private $email; |
62
|
|
|
|
63
|
|
|
/** @var string|null Developer address */ |
64
|
|
|
private $address; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Creates an object with information about the developer of Google Play. |
68
|
|
|
* |
69
|
|
|
* @param DeveloperBuilder $builder developer builder |
70
|
|
|
* |
71
|
|
|
* @internal |
72
|
|
|
*/ |
73
|
12 |
|
public function __construct(DeveloperBuilder $builder) |
74
|
|
|
{ |
75
|
12 |
|
$this->id = $builder->getId(); |
76
|
12 |
|
$this->url = $builder->getUrl(); |
77
|
12 |
|
$this->name = $builder->getName(); |
78
|
12 |
|
$this->description = $builder->getDescription(); |
79
|
12 |
|
$this->website = $builder->getWebsite(); |
80
|
12 |
|
$this->icon = $builder->getIcon(); |
81
|
12 |
|
$this->cover = $builder->getCover(); |
82
|
12 |
|
$this->email = $builder->getEmail(); |
83
|
12 |
|
$this->address = $builder->getAddress(); |
84
|
|
|
|
85
|
12 |
|
if (empty($this->id)) { |
86
|
|
|
throw new \InvalidArgumentException( |
87
|
|
|
'Developer id cannot be null or empty. ' |
88
|
|
|
. 'Solution: $developerBuilder->setId(...);' |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
12 |
|
if (empty($this->url)) { |
93
|
|
|
throw new \InvalidArgumentException( |
94
|
|
|
'Developer url cannot be null or empty. ' |
95
|
|
|
. 'Solution: $developerBuilder->setUrl(...);' |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
12 |
|
if (empty($this->name)) { |
100
|
|
|
throw new \InvalidArgumentException( |
101
|
|
|
'Developer name cannot be null or empty. ' |
102
|
|
|
. 'Solution: $developerBuilder->setName(...);' |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns developer id. |
109
|
|
|
* |
110
|
|
|
* @return string developer id |
111
|
|
|
*/ |
112
|
3 |
|
public function getId(): string |
113
|
|
|
{ |
114
|
3 |
|
return $this->id; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns the URL of the developer’s page in Google Play. |
119
|
|
|
* |
120
|
|
|
* @return string developer page url |
121
|
|
|
*/ |
122
|
1 |
|
public function getUrl(): string |
123
|
|
|
{ |
124
|
1 |
|
return $this->url; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns the name of the developer. |
129
|
|
|
* |
130
|
|
|
* @return string Developer name |
131
|
|
|
*/ |
132
|
1 |
|
public function getName(): string |
133
|
|
|
{ |
134
|
1 |
|
return $this->name; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns a description of the developer. |
139
|
|
|
* |
140
|
|
|
* @return string|null description of the developer or `null` |
141
|
|
|
*/ |
142
|
1 |
|
public function getDescription(): ?string |
143
|
|
|
{ |
144
|
1 |
|
return $this->description; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns the developer's website. |
149
|
|
|
* |
150
|
|
|
* @return string|null developer website or `null` |
151
|
|
|
*/ |
152
|
1 |
|
public function getWebsite(): ?string |
153
|
|
|
{ |
154
|
1 |
|
return $this->website; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Returns the developer icon. |
159
|
|
|
* |
160
|
|
|
* @return GoogleImage|null developer icon or `null` |
161
|
|
|
*/ |
162
|
1 |
|
public function getIcon(): ?GoogleImage |
163
|
|
|
{ |
164
|
1 |
|
return $this->icon; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns the developer cover. |
169
|
|
|
* |
170
|
|
|
* @return GoogleImage|null developer cover or `null` |
171
|
|
|
*/ |
172
|
1 |
|
public function getCover(): ?GoogleImage |
173
|
|
|
{ |
174
|
1 |
|
return $this->cover; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Returns developer email. |
179
|
|
|
* |
180
|
|
|
* @return string|null developer email or `null` |
181
|
|
|
*/ |
182
|
1 |
|
public function getEmail(): ?string |
183
|
|
|
{ |
184
|
1 |
|
return $this->email; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Returns the address of the developer. |
189
|
|
|
* |
190
|
|
|
* @return string|null developer address or `null` |
191
|
|
|
*/ |
192
|
1 |
|
public function getAddress(): ?string |
193
|
|
|
{ |
194
|
1 |
|
return $this->address; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Creates a new developer builder. |
199
|
|
|
* |
200
|
|
|
* @return DeveloperBuilder developer builder |
201
|
|
|
* |
202
|
|
|
* @internal |
203
|
|
|
*/ |
204
|
12 |
|
public static function newBuilder(): DeveloperBuilder |
205
|
|
|
{ |
206
|
12 |
|
return new DeveloperBuilder(); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Checks for equality of developer. |
211
|
|
|
* |
212
|
|
|
* @param Developer $otherDeveloper developer with which is compared |
213
|
|
|
* |
214
|
|
|
* @return bool `true` if the contents of the objects being changed are the same |
215
|
|
|
* and `false` if the objects contain different data |
216
|
|
|
* |
217
|
|
|
* @internal |
218
|
|
|
*/ |
219
|
|
|
public function equals(self $otherDeveloper): bool |
220
|
|
|
{ |
221
|
|
|
if ($this->id !== $otherDeveloper->id) { |
222
|
|
|
return false; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
if ($this->name !== $otherDeveloper->name) { |
226
|
|
|
return false; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
if ($this->description !== $otherDeveloper->description) { |
230
|
|
|
return false; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
if ($this->icon !== null && $otherDeveloper->icon !== null) { |
234
|
|
|
if ($this->icon->getOriginalSizeUrl() !== $otherDeveloper->icon->getOriginalSizeUrl()) { |
235
|
|
|
return false; |
236
|
|
|
} |
237
|
|
|
} elseif ($this->icon !== $otherDeveloper->icon) { |
238
|
|
|
return false; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
if ( |
242
|
|
|
$this->cover !== null |
243
|
|
|
&& $otherDeveloper->cover !== null |
244
|
|
|
&& $this->cover->getOriginalSizeUrl() !== $otherDeveloper->cover->getOriginalSizeUrl() |
245
|
|
|
) { |
246
|
|
|
return false; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
return $this->cover === $otherDeveloper->cover; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Returns class properties as an array. |
254
|
|
|
* |
255
|
|
|
* @return array class properties as an array |
256
|
|
|
*/ |
257
|
|
|
public function asArray(): array |
258
|
|
|
{ |
259
|
|
|
return [ |
260
|
|
|
'id' => $this->id, |
261
|
|
|
'url' => $this->url, |
262
|
|
|
'name' => $this->name, |
263
|
|
|
'description' => $this->description, |
264
|
|
|
'website' => $this->website, |
265
|
|
|
'icon' => $this->icon !== null ? $this->icon->getUrl() : null, |
266
|
|
|
'cover' => $this->cover !== null ? $this->cover->getUrl() : null, |
267
|
|
|
'email' => $this->email, |
268
|
|
|
'address' => $this->address, |
269
|
|
|
]; |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|