Skip to content

Commit 9211b3b

Browse files
authored
Merge pull request #3 from jijihohococo/refactor
Refactor ENV and helpers: streamline error handling and improve readability
2 parents b57bf6c + c800b0a commit 9211b3b

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/ENV.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ class ENV
1212

1313
public static function set(string $filePath)
1414
{
15-
if (is_readable($filePath)) {
16-
self::$comma = rand();
17-
self::$env = implode(self::$comma, file($filePath));
18-
} else {
15+
if (!is_readable($filePath)) {
1916
throw new Exception($filePath . ' is not exist', 1);
2017
}
18+
self::$comma = rand();
19+
self::$env = implode(self::$comma, file($filePath));
2120
}
2221

2322
public static function get()

src/helpers.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ function gete(string $data)
2323
$dataset = ENV::getDataset();
2424
if (isset($dataset[$data])) {
2525
return preg_replace('/\s+/', '', $dataset[$data]);
26-
} else {
27-
$data = $data . '=';
28-
$env = ENV::get();
29-
$comma = ENV::getComma();
30-
if ($env == null) {
31-
throw new \Exception("Please set the file path firstly", 1);
32-
}
33-
$getData = strpos($env, $data) !== false ? getStringBetween($env, $data, $comma) : null;
34-
ENV::setDataset($previousData, $getData);
35-
return preg_replace('/\s+/', '', $getData);
3626
}
27+
$data = $data . '=';
28+
$env = ENV::get();
29+
$comma = ENV::getComma();
30+
if ($env == null) {
31+
throw new \Exception("Please set the file path firstly", 1);
32+
}
33+
$getData = strpos($env, $data) !== false ? getStringBetween($env, $data, $comma) : null;
34+
ENV::setDataset($previousData, $getData);
35+
return preg_replace('/\s+/', '', $getData);
3736
}
3837
}

0 commit comments

Comments
 (0)