Skip to content

Commit

Permalink
created separate Processing.php file
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-xz committed Jan 16, 2024
1 parent 6e69f1a commit 31d7377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/Differ/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

namespace Differ\Differ;

function getJsonContent($pathToFile)
{
if (file_exists($pathToFile)) {
$content = file_get_contents($pathToFile, true);
return json_decode($content, true);
}
throw new \Exception("File do not found: \"{$pathToFile}\"!");
}
use Differ\Processing;

function genDiff($pathToFile1, $pathToFile2)
{
$firstFile = getJsonContent($pathToFile1);
$secondFile = getJsonContent($pathToFile2);
$firstFile = Processing\getJsonContent($pathToFile1);
$secondFile = Processing\getJsonContent($pathToFile2);
$mergedFiles = array_merge($secondFile, $firstFile);
ksort($mergedFiles);
$result = array_map(function ($key, $value) use ($firstFile, $secondFile) {
Expand Down
12 changes: 12 additions & 0 deletions src/Processing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Differ\Processing;

function getJsonContent($pathToFile)
{
if (file_exists($pathToFile)) {
$content = file_get_contents($pathToFile, true);
return json_decode($content, true);
}
throw new \Exception("File do not found: \"{$pathToFile}\"!");
}

0 comments on commit 31d7377

Please sign in to comment.