Skip to content

Commit

Permalink
cut dupe code
Browse files Browse the repository at this point in the history
  • Loading branch information
cancan101 committed Nov 22, 2024
1 parent db629cb commit 43b8400
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/DataSource/Interpreter/JsonFileInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ class JsonFileInterpreter extends AbstractInterpreter
*/
protected $cachedFilePath = null;

protected function loadDataRaw(string $path): array {
$content = file_get_contents($path);
return json_decode($this->prepareContent($content), true);
}

protected function loadData(string $path): array
{
if ($this->cachedFilePath !== $path || empty($this->cachedContent)) {
$content = file_get_contents($path);
$data = json_decode($this->prepareContent($content), true);
$data = $this->loadDataRaw($path);
} else {
$data = $this->cachedContent;
}
Expand Down Expand Up @@ -93,9 +97,7 @@ public function fileValid(string $path, bool $originalFilename = false): bool
}
}

$content = file_get_contents($path);

$data = json_decode($this->prepareContent($content), true);
$data = $this->loadDataRaw($path);

if (json_last_error() === JSON_ERROR_NONE) {
$this->cachedContent = $data;
Expand Down

0 comments on commit 43b8400

Please sign in to comment.