Skip to content

Commit c5262fa

Browse files
committed
change & property to static
1 parent 829cdab commit c5262fa

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

src/Reader.php

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
class Reader
99
{
1010
private $fetchNew = false;
11-
private $database;
12-
private $filemtime;
11+
12+
private static $database;
13+
private static $filemtime;
1314

1415
public $valid = false;
1516
public $nik;
@@ -56,20 +57,6 @@ public function setNik(string $nik)
5657
{
5758
$this->nik = $nik;
5859

59-
if (
60-
! is_string($this->nik)
61-
|| ! preg_match("/^[0-9]+$/is", $this->nik)
62-
|| ! strlen($this->nik) === 16
63-
) {
64-
// throw new Exceptions\InvalidNikNumberException(sprintf(
65-
// 'NIK number should be a 16-digit numeric string. Got: %s (%d)',
66-
// gettype($nik),
67-
// strlen($nik)
68-
// ));
69-
70-
$this->valid = false;
71-
}
72-
7360
return $this;
7461
}
7562

@@ -130,7 +117,7 @@ public function setDatabase(string $file)
130117
));
131118
}
132119

133-
if ($this->filemtime <= filemtime($file)) {
120+
if (static::$filemtime <= filemtime($file)) {
134121
$database = file_get_contents($file);
135122
$database = json_decode($database);
136123

@@ -142,8 +129,8 @@ public function setDatabase(string $file)
142129
));
143130
}
144131

145-
$this->database = $database;
146-
$this->filemtime = filemtime($file);
132+
static::$database = $database;
133+
static::$filemtime = filemtime($file);
147134
}
148135

149136
return $this;
@@ -163,8 +150,8 @@ public function getProvince()
163150
$this->province_id = substr($this->nik, 0, 2);
164151

165152
return $this->province = (
166-
isset($this->database->provinces->{$this->province_id})
167-
? $this->database->provinces->{$this->province_id}
153+
isset(static::$database->provinces->{$this->province_id})
154+
? static::$database->provinces->{$this->province_id}
168155
: null
169156
);
170157
}
@@ -183,8 +170,8 @@ public function getCity()
183170
$this->city_id = substr($this->nik, 0, 4);
184171

185172
return $this->city = (
186-
isset($this->database->cities->{$this->city_id})
187-
? $this->database->cities->{$this->city_id}
173+
isset(static::$database->cities->{$this->city_id})
174+
? static::$database->cities->{$this->city_id}
188175
: null
189176
);
190177
}
@@ -203,8 +190,8 @@ public function getSubdistrict()
203190
$this->subdistrict_id = substr($this->nik, 0, 6);
204191

205192
$this->subdistrict = (
206-
isset($this->database->subdistricts->{$this->subdistrict_id})
207-
? $this->database->subdistricts->{$this->subdistrict_id}
193+
isset(static::$database->subdistricts->{$this->subdistrict_id})
194+
? static::$database->subdistricts->{$this->subdistrict_id}
208195
: null
209196
);
210197

@@ -230,8 +217,8 @@ public function getPostalCode()
230217
$code = substr($this->nik, 0, 6);
231218

232219
$subdistrict = (
233-
isset($this->database->subdistricts->{$code})
234-
? $this->database->subdistricts->{$code}
220+
isset(static::$database->subdistricts->{$code})
221+
? static::$database->subdistricts->{$code}
235222
: null
236223
);
237224

@@ -339,7 +326,7 @@ public function getZodiac()
339326
$day = $day - 40;
340327
}
341328

342-
foreach ($this->database->zodiacs as $data) {
329+
foreach (static::$database->zodiacs as $data) {
343330
$range = explode('-', $data[0]);
344331
$rangeStart = explode('/', $range[0]);
345332
$rangeEnd = explode('/', $range[1]);

0 commit comments

Comments
 (0)