@@ -18,46 +18,42 @@ private function constructContent($accum, $item)
1818 return $ accum .= "\n " . $ item ;
1919 }
2020
21- public function execute (array $ data ): ? array
21+ public function execute (CommandInterface $ command = null ): CommandInterface
2222 {
23+ $ file1Content = $ command ->getFilesContent ()['FILE1 ' ];
24+ $ file2Content = $ command ->getFilesContent ()['FILE2 ' ];
2325
2426 $ this ->filesContent [] = "file1.json content: \n" ;
2527 $ this ->filesContent [] = array_reduce (
26- $ data [ ' file1 ' ] ,
28+ $ file1Content ,
2729 [$ this , 'constructContent ' ],
2830 "{ "
2931 ) . "\r} \n" ;
3032
3133 $ this ->filesContent [] = "file2.json content: \n" ;
3234 $ this ->filesContent [] = array_reduce (
33- $ data [ ' file2 ' ] ,
35+ $ file2Content ,
3436 [$ this , 'constructContent ' ],
3537 "{ "
3638 ) . "\n} \n" ;
3739
38- $ file1Array = $ data ['file1 ' ];
39- $ file1Keys = array_keys ($ file1Array );
40- $ file2Array = $ data ['file2 ' ];
40+ $ file1Keys = array_keys ($ file1Content );
4141 $ this ->filesDiffContent = array_map (
42- function ($ file1Key ) use ($ file1Array , $ file2Array ) {
43- if (array_key_exists ($ file1Key , $ file2Array )) {
44- if (!strcmp ($ file1Array [$ file1Key ], $ file2Array [$ file1Key ])) {
45- return " " . $ file1Array [$ file1Key ] . "\n" ;
42+ function ($ file1Key ) use ($ file1Content , $ file2Content ) {
43+ if (array_key_exists ($ file1Key , $ file2Content )) {
44+ if (!strcmp ($ file1Content [$ file1Key ], $ file2Content [$ file1Key ])) {
45+ return " " . $ file1Content [$ file1Key ] . "\n" ;
4646 } else {
47- return " - " . $ file1Array [$ file1Key ] . "\n" .
48- " + " . $ file2Array [$ file1Key ] . "\n" ;
47+ return " - " . $ file1Content [$ file1Key ] . "\n" .
48+ " + " . $ file2Content [$ file1Key ] . "\n" ;
4949 }
5050 } else {
51- return " - " . $ file1Array [$ file1Key ] . "\n" ;
51+ return " - " . $ file1Content [$ file1Key ] . "\n" ;
5252 }
5353 },
5454 $ file1Keys
5555 );
56- return
57- [
58- "content " => $ this ->filesContent ,
59- "diff " => $ this ->filesDiffContent
60- ];
56+ return $ this ;
6157 }
6258
6359 public function showContentToConsole ()
@@ -69,4 +65,9 @@ public function showDiffsToConsole()
6965 {
7066 echo "{ \n" . implode ("" , $ this ->filesDiffContent ) . "} \n" ;
7167 }
68+
69+ public function getDiffs ()
70+ {
71+ return "{ \n" . implode ("" , $ this ->filesDiffContent ) . "} \n" ;
72+ }
7273}
0 commit comments