-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified files, new logic in modules, aded formatter "plain"
- Loading branch information
1 parent
9be29df
commit 511582d
Showing
8 changed files
with
156 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
## Hexlet tests and linter status: | ||
# Hexlet tests and linter status: | ||
[![Actions Status](https://github.com/RasmuS2024/php-project-48/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/RasmuS2024/php-project-48/actions) | ||
## Codeclimate maintainability status: | ||
# Codeclimate maintainability status: | ||
<a href="https://codeclimate.com/github/RasmuS2024/php-project-48/maintainability"><img src="https://api.codeclimate.com/v1/badges/dd978260caa754e3367b/maintainability" /></a> | ||
## Codeclimate Test Coverage status: | ||
# Codeclimate Test Coverage status: | ||
<a href="https://codeclimate.com/github/RasmuS2024/php-project-48/test_coverage"><img src="https://api.codeclimate.com/v1/badges/dd978260caa754e3367b/test_coverage" /></a> | ||
|
||
|
||
## Gendiff process with json files in asciinema: | ||
# Gendiff process with json files in asciinema: | ||
<a href="https://asciinema.org/a/sajdPQG2NqP2Ky51Kyp4SDpBp" target="_blank"><img src="https://asciinema.org/a/sajdPQG2NqP2Ky51Kyp4SDpBp.svg" width="400" height="300" /></a> | ||
|
||
## Gendiff process with YAML files in asciinema: | ||
# Gendiff process with YAML files in asciinema: | ||
<a href="https://asciinema.org/a/rV1BXXmxURj3LKG9UDLQcDJvi" target="_blank"><img src="https://asciinema.org/a/rV1BXXmxURj3LKG9UDLQcDJvi.svg" width="400" height="300" /></a> | ||
|
||
## Gendiff process with json and YAML files with nested structure in asciinema: | ||
<a href="https://asciinema.org/a/nUzyU01TNMRxl5NX8fDdVE54V" target="_blank"><img src="https://asciinema.org/a/nUzyU01TNMRxl5NX8fDdVE54V.svg" width="400" height="300" /></a> | ||
# Gendiff process with json and YAML files with nested structure in asciinema: | ||
<a href="https://asciinema.org/a/nUzyU01TNMRxl5NX8fDdVE54V" target="_blank"><img src="https://asciinema.org/a/nUzyU01TNMRxl5NX8fDdVE54V.svg" width="400" height="300" /></a> | ||
|
||
# Gendiff process with select out format in asciinema: | ||
<a href="https://asciinema.org/a/82H9oUqEatG1FHpbsW9dhUKGH" target="_blank"><img src="https://asciinema.org/a/82H9oUqEatG1FHpbsW9dhUKGH.svg" width="400" height="300" /></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<coverage generated="1728822010"> | ||
<project timestamp="1728822010"> | ||
<file name="/home/user1/projects/php-project-48/src/Diff.php"> | ||
<line num="7" type="stmt" count="1"/> | ||
<line num="8" type="stmt" count="1"/> | ||
<line num="9" type="stmt" count="1"/> | ||
<line num="10" type="stmt" count="1"/> | ||
<line num="11" type="stmt" count="1"/> | ||
<coverage generated="1729746185"> | ||
<project timestamp="1729746185"> | ||
<file name="/home/user1/projects/php-project-48/src/Differ.php"> | ||
<line num="10" type="stmt" count="5"/> | ||
<line num="11" type="stmt" count="5"/> | ||
<line num="12" type="stmt" count="5"/> | ||
<line num="13" type="stmt" count="5"/> | ||
<line num="14" type="stmt" count="5"/> | ||
<line num="19" type="stmt" count="5"/> | ||
<line num="20" type="stmt" count="5"/> | ||
<line num="21" type="stmt" count="5"/> | ||
<line num="22" type="stmt" count="5"/> | ||
<line num="23" type="stmt" count="5"/> | ||
<line num="24" type="stmt" count="5"/> | ||
<line num="29" type="stmt" count="3"/> | ||
<line num="30" type="stmt" count="3"/> | ||
<line num="31" type="stmt" count="3"/> | ||
<line num="33" type="stmt" count="3"/> | ||
<line num="35" type="stmt" count="3"/> | ||
<line num="36" type="stmt" count="3"/> | ||
<line num="41" type="stmt" count="5"/> | ||
<line num="42" type="stmt" count="5"/> | ||
<line num="43" type="stmt" count="5"/> | ||
<line num="44" type="stmt" count="5"/> | ||
<line num="45" type="stmt" count="3"/> | ||
<line num="47" type="stmt" count="5"/> | ||
<line num="49" type="stmt" count="5"/> | ||
<line num="50" type="stmt" count="5"/> | ||
<line num="51" type="stmt" count="5"/> | ||
<line num="52" type="stmt" count="3"/> | ||
<line num="54" type="stmt" count="5"/> | ||
<line num="56" type="stmt" count="5"/> | ||
<line num="58" type="stmt" count="5"/> | ||
<line num="59" type="stmt" count="5"/> | ||
<line num="60" type="stmt" count="5"/> | ||
<line num="61" type="stmt" count="3"/> | ||
<line num="63" type="stmt" count="5"/> | ||
<line num="64" type="stmt" count="5"/> | ||
<line num="66" type="stmt" count="5"/> | ||
<line num="67" type="stmt" count="3"/> | ||
<line num="69" type="stmt" count="5"/> | ||
<line num="70" type="stmt" count="0"/> | ||
<line num="72" type="stmt" count="5"/> | ||
<line num="74" type="stmt" count="5"/> | ||
<line num="75" type="stmt" count="5"/> | ||
<metrics loc="77" ncloc="77" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="42" coveredstatements="41" elements="42" coveredelements="41"/> | ||
</file> | ||
<file name="/home/user1/projects/php-project-48/src/Formatters.php"> | ||
<line num="10" type="stmt" count="5"/> | ||
<line num="11" type="stmt" count="4"/> | ||
<line num="12" type="stmt" count="1"/> | ||
<line num="13" type="stmt" count="1"/> | ||
<line num="14" type="stmt" count="1"/> | ||
<line num="15" type="stmt" count="1"/> | ||
<line num="16" type="stmt" count="1"/> | ||
<line num="18" type="stmt" count="1"/> | ||
<line num="19" type="stmt" count="1"/> | ||
<line num="20" type="stmt" count="1"/> | ||
<line num="21" type="stmt" count="0"/> | ||
<line num="23" type="stmt" count="1"/> | ||
<line num="24" type="stmt" count="1"/> | ||
<line num="26" type="stmt" count="1"/> | ||
<line num="27" type="stmt" count="1"/> | ||
<line num="30" type="stmt" count="1"/> | ||
<line num="33" type="stmt" count="1"/> | ||
<line num="34" type="stmt" count="1"/> | ||
<line num="35" type="stmt" count="1"/> | ||
<line num="36" type="stmt" count="1"/> | ||
<line num="39" type="stmt" count="1"/> | ||
<line num="42" type="stmt" count="1"/> | ||
<line num="43" type="stmt" count="1"/> | ||
<metrics loc="45" ncloc="45" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="26" coveredstatements="25" elements="26" coveredelements="25"/> | ||
<line num="13" type="stmt" count="5"/> | ||
<line num="14" type="stmt" count="5"/> | ||
<metrics loc="16" ncloc="16" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="5" coveredstatements="5" elements="5" coveredelements="5"/> | ||
</file> | ||
<file name="/home/user1/projects/php-project-48/src/Parsers.php"> | ||
<line num="9" type="stmt" count="5"/> | ||
<line num="10" type="stmt" count="5"/> | ||
<line num="11" type="stmt" count="3"/> | ||
<line num="12" type="stmt" count="2"/> | ||
<line num="13" type="stmt" count="2"/> | ||
<line num="14" type="stmt" count="5"/> | ||
<line num="15" type="stmt" count="5"/> | ||
<metrics loc="17" ncloc="17" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="7" coveredstatements="7" elements="7" coveredelements="7"/> | ||
</file> | ||
<metrics files="1" loc="45" ncloc="45" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="26" coveredstatements="25" elements="26" coveredelements="25"/> | ||
<metrics files="3" loc="110" ncloc="110" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="54" coveredstatements="53" elements="54" coveredelements="53"/> | ||
</project> | ||
</coverage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace GenDiff\Differ; | ||
|
||
use function GenDiff\Formatters\formatSelect; | ||
use function GenDiff\Parsers\fileParser; | ||
|
||
function genDiff(mixed $file1Path, mixed $file2Path, string $formatName = 'stylish'): string | ||
{ | ||
$data1 = fileParser($file1Path); | ||
$data2 = fileParser($file2Path); | ||
$dataDiff = filesDiffer($data1, $data2); | ||
$result = formatSelect($dataDiff, $formatName); | ||
return $result; | ||
} | ||
|
||
function getSortedKeys(array $json1, array $json2): array | ||
{ | ||
$keys1 = array_keys($json1); | ||
$keys2 = array_keys($json2); | ||
$keys = array_merge($keys1, $keys2); | ||
$keys = array_unique($keys); | ||
sort($keys, SORT_STRING); | ||
return $keys; | ||
} | ||
|
||
function arrayKeysInsert(array $array): array | ||
{ | ||
$value1 = array_map(function ($keyIn, $valueIn) { | ||
if (!is_array($valueIn)) { | ||
return ['type' => ' ', 'key' => $keyIn, 'value' => $valueIn]; | ||
} else { | ||
return ['type' => ' ', 'key' => $keyIn, 'value' => arrayKeysInsert($valueIn)]; | ||
} | ||
}, array_keys($array), $array); | ||
return $value1; | ||
} | ||
|
||
function filesDiffer(mixed $data1, mixed $data2): mixed | ||
{ | ||
$sortedKeys = getSortedKeys($data1, $data2); | ||
$data = array_map(function ($key) use ($data1, $data2) { | ||
if (!array_key_exists($key, $data1)) { | ||
if (is_array($data2[$key])) { | ||
$value2 = arrayKeysInsert($data2[$key]); | ||
} else { | ||
$value2 = $data2[$key]; | ||
} | ||
return ['type' => '+', 'key' => $key, 'value' => $value2]; | ||
} elseif (!array_key_exists($key, $data2)) { | ||
if (is_array($data1[$key])) { | ||
$value1 = arrayKeysInsert($data1[$key]); | ||
} else { | ||
$value1 = $data1[$key]; | ||
} | ||
return ['type' => '-', 'key' => $key, 'value' => $value1]; | ||
} | ||
$value1 = $data1[$key]; | ||
$value2 = $data2[$key]; | ||
if (is_array($value1) && is_array($value2)) { | ||
return ['type' => ' ', 'key' => $key, 'value' => filesDiffer($value1, $value2)]; | ||
} | ||
if ($value1 === $value2) { | ||
return ['type' => ' ', 'key' => $key, 'value' => $value1]; | ||
} else { | ||
if (is_array($value1)) { | ||
$value1 = arrayKeysInsert($value1); | ||
} | ||
if (is_array($value2)) { | ||
$value2 = arrayKeysInsert($value2); | ||
} | ||
return ['type' => '_', 'key' => $key, 'value' => $value1, 'new_value' => $value2]; | ||
} | ||
}, $sortedKeys); | ||
return $data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters