1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Nelexa\GPlay\Model; |
5
|
|
|
|
6
|
|
|
use Nelexa\GPlay\Model\Builder\AppBuilder; |
7
|
|
|
|
8
|
|
|
class App |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $id; |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $url; |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $locale; |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $name; |
26
|
|
|
/** |
27
|
|
|
* @var string|null |
28
|
|
|
*/ |
29
|
|
|
private $summary; |
30
|
|
|
/** |
31
|
|
|
* @var Developer |
32
|
|
|
*/ |
33
|
|
|
private $developer; |
34
|
|
|
/** |
35
|
|
|
* @var GoogleImage |
36
|
|
|
*/ |
37
|
|
|
private $icon; |
38
|
|
|
/** |
39
|
|
|
* @var float |
40
|
|
|
*/ |
41
|
|
|
private $score; |
42
|
|
|
/** |
43
|
|
|
* @var string|null |
44
|
|
|
*/ |
45
|
|
|
private $priceText; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* App constructor. |
49
|
|
|
* |
50
|
|
|
* @param AppBuilder $builder |
51
|
|
|
* @throws \InvalidArgumentException |
52
|
|
|
*/ |
53
|
|
|
public function __construct(AppBuilder $builder) |
54
|
|
|
{ |
55
|
|
|
$this->id = $builder->getId(); |
56
|
|
|
$this->url = $builder->getUrl(); |
57
|
|
|
$this->locale = $builder->getLocale(); |
58
|
|
|
$this->name = $builder->getName(); |
59
|
|
|
$this->summary = $builder->getSummary(); |
60
|
|
|
$this->developer = $builder->getDeveloper(); |
61
|
|
|
$this->icon = $builder->getIcon(); |
62
|
|
|
$this->score = $builder->getScore(); |
63
|
|
|
$this->priceText = $builder->getPriceText(); |
64
|
|
|
|
65
|
|
|
if (empty($this->id)) { |
66
|
|
|
throw new \InvalidArgumentException('$id cannot be null or empty. Solution: $appBuilder->setId(...);'); |
67
|
|
|
} |
68
|
|
|
if (empty($this->url)) { |
69
|
|
|
throw new \InvalidArgumentException('$url cannot be null or empty. Solution: $appBuilder->setId(...); or $appBuilder->setUrl(...);'); |
70
|
|
|
} |
71
|
|
|
if (empty($this->locale)) { |
72
|
|
|
throw new \InvalidArgumentException('$locale cannot be null or empty. Solution: $appBuilder->setLocale(...);'); |
73
|
|
|
} |
74
|
|
|
if (empty($this->name)) { |
75
|
|
|
throw new \InvalidArgumentException('$name cannot be null or empty. Solution: $appBuilder->setName(...);'); |
76
|
|
|
} |
77
|
|
|
if ($this->developer === null) { |
78
|
|
|
throw new \InvalidArgumentException('$developer cannot be null. Solution: $appBuilder->setDeveloper(...);'); |
79
|
|
|
} |
80
|
|
|
if ($this->icon === null) { |
81
|
|
|
throw new \InvalidArgumentException('$icon cannot be null. Solution: $appBuilder->setIcon(...);'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getId(): string |
89
|
|
|
{ |
90
|
|
|
return $this->id; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function getUrl(): string |
97
|
|
|
{ |
98
|
|
|
return $this->url; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function getLocale(): string |
105
|
|
|
{ |
106
|
|
|
return $this->locale; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getName(): string |
113
|
|
|
{ |
114
|
|
|
return $this->name; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string|null |
119
|
|
|
*/ |
120
|
|
|
public function getSummary(): ?string |
121
|
|
|
{ |
122
|
|
|
return $this->summary; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return Developer |
127
|
|
|
*/ |
128
|
|
|
public function getDeveloper(): Developer |
129
|
|
|
{ |
130
|
|
|
return $this->developer; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return GoogleImage |
135
|
|
|
*/ |
136
|
|
|
public function getIcon(): GoogleImage |
137
|
|
|
{ |
138
|
|
|
return $this->icon; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return float |
143
|
|
|
*/ |
144
|
|
|
public function getScore(): float |
145
|
|
|
{ |
146
|
|
|
return $this->score; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string|null |
151
|
|
|
*/ |
152
|
|
|
public function getPriceText(): ?string |
153
|
|
|
{ |
154
|
|
|
return $this->priceText; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return bool |
159
|
|
|
*/ |
160
|
|
|
public function isFree(): bool |
161
|
|
|
{ |
162
|
|
|
return $this->priceText === null; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return AppBuilder |
167
|
|
|
*/ |
168
|
|
|
public static function newBuilder(): AppBuilder |
169
|
|
|
{ |
170
|
|
|
return new AppBuilder(); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|