Skip to content

Commit

Permalink
fixed Diff.php
Browse files Browse the repository at this point in the history
  • Loading branch information
artengin committed Jul 2, 2024
1 parent ace4903 commit 0519802
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
[![Actions Status](https://github.com/artengin/php-project-48/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/artengin/php-project-48/actions)

### Github Actions and code Climate:
[![Actions Status](https://github.com/artengin/php-project-48/actions/workflows/test.yml/badge.svg)](https://github.com/artengin/php-project-48/actions)
[![Actions Status](https://github.com/artengin/php-project-48/actions/workflows/test.yml/badge.svg)](https://github.com/artengin/php-project-48/actions) [![Maintainability](https://api.codeclimate.com/v1/badges/debcd3dc6422436345f5/maintainability)](https://codeclimate.com/github/artengin/php-project-48/maintainability)
9 changes: 3 additions & 6 deletions src/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,27 @@ function findDiff(array $first, array $second): string
ksort($mergeArray);

$resultDiff = array_reduce(array_keys($mergeArray), function ($acc, $key) use ($first, $second) {
$firstValue = isBool($first[$key]);
$secondValue = isBool($second[$key]);
$checkFirst = array_key_exists($key, $first);
$checkSecond = array_key_exists($key, $second);
if ($checkFirst && $checkSecond) {
if ($first[$key] === $second[$key]) {
$firstValue = isBool($first[$key]);
$acc[] = " {$key}: {$firstValue}";
return $acc;
}
$firstValue = isBool($first[$key]);
$secondValue = isBool($second[$key]);
$acc[] = "- {$key}: {$firstValue}";
$acc[] = "+ {$key}: {$secondValue}";
return $acc;
}
if ($checkFirst) {
$firstValue = isBool($first[$key]);
$acc[] = "- {$key}: {$firstValue}";
return $acc;
}
$secondValue = isBool($second[$key]);
$acc[] = "+ {$key}: {$secondValue}";
return $acc;
}, []);
return implode("\n", $resultDiff) . "\n";
return implode("\n", $resultDiff);
}
function isBool($string)
{
Expand Down

0 comments on commit 0519802

Please sign in to comment.