Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e11141

Browse files
committed
Enhance compare_yaml_hashmaps.php
1 parent da36e8c commit 1e11141

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

‎compare_yaml_hashmaps.php‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require_once __DIR__.'/vendor/autoload.php';
3+
require_once __DIR__ . '/vendor/autoload.php';
44

55
use Symfony\Component\Yaml\Yaml;
66

@@ -60,29 +60,47 @@ function extractArrayFromFile($filepath, $rootNode)
6060

6161
$inFile1ButNotInFile2 = [];
6262
$inFile2ButNotInFile1 = [];
63+
$sameKeyDifferentValues = [];
6364

6465
foreach ($list1 as $key => $value) {
6566
if (!array_key_exists($key, $list2)) {
6667
$inFile1ButNotInFile2[$key] = $value;
68+
} elseif ($list1[$key] !== $list2[$key]) {
69+
$sameKeyDifferentValues[$key] = $list1[$key] . ' / ' . $list2[$key];
6770
}
6871
}
6972
foreach ($list2 as $key => $value) {
7073
if (!array_key_exists($key, $list1)) {
7174
$inFile2ButNotInFile1[$key] = $value;
75+
} elseif ($list2[$key] !== $list1[$key]) {
76+
$sameKeyDifferentValues[$key] = $list1[$key] . ' / ' . $list2[$key];
7277
}
7378
}
7479

7580

7681
// echo result
7782
echo TextColorWriter::textColor('Done', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
78-
echo TextColorWriter::textColor('Found in file 1 but not in file 2:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
7983

80-
foreach ($inFile1ButNotInFile2 as $key => $value) {
81-
echo ' - ' . $key . PHP_EOL;
84+
if (false === empty($inFile1ButNotInFile2)) {
85+
echo TextColorWriter::textColor('Found in file 1 but not in file 2:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
86+
87+
foreach ($inFile1ButNotInFile2 as $key => $value) {
88+
echo ' - ' . $key . PHP_EOL;
89+
}
8290
}
8391

84-
echo TextColorWriter::textColor('Found in file 2 but not in file 1:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
92+
if (false === empty($inFile2ButNotInFile1)) {
93+
echo TextColorWriter::textColor('Found in file 2 but not in file 1:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
8594

86-
foreach ($inFile2ButNotInFile1 as $key => $value) {
87-
echo ' - ' . $key . PHP_EOL;
95+
foreach ($inFile2ButNotInFile1 as $key => $value) {
96+
echo ' - ' . $key . PHP_EOL;
97+
}
98+
}
99+
100+
if (false === empty($sameKeyDifferentValues)) {
101+
echo TextColorWriter::textColor('Key in both hashmaps but different value:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
102+
103+
foreach ($sameKeyDifferentValues as $key => $value) {
104+
echo ' - ' . $key . ' : ' . $value . PHP_EOL;
105+
}
88106
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /