| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace AHJ\ApprovalTests; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  | final class ReceivedMap | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 | 6 |  |     public function create(array $input, array $output): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 | 6 |  |         $received = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 | 6 |  |         foreach ($input as $inputKey => $inputValue) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 | 6 |  |             $received[$inputKey] = '[' . $this->serializeMixedType($inputValue) . '] -> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 | 2 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         foreach ($output as $outputKey => $outputValue) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 6 |  |             $received[$outputKey] = $received[$outputKey] . '[' . $this->serializeMixedType($outputValue) . ']'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 4 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 21 |  |  |         return $this->cleanAndFlatten($received); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 23 | 6 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 | 6 |  |     private function serializeMixedType($inputValue, string $currentConcatenations = ''): string | 
            
                                                                        
                            
            
                                    
            
            
                | 25 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         $concatenations = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 | 6 |  |         if ('string' === gettype($inputValue)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 5 |  |             return $currentConcatenations . $inputValue; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         foreach ($inputValue as $item) { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 6 |  |             if ('array' === gettype($item) || 'object' === gettype($item)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |                 $concatenations .= '[' . $this->serializeMixedType($item, $concatenations) . ']'; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |                 $concatenations .= $item . ', '; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         return $concatenations; | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * @param array $received | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      *                        Example: | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      *                        [ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      *                        [0] => '[foo, 0, [bar, 10, ]] -> [foo, 10, [bar, 60, ]]', | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      *                        [1] => '[foo, 10, [bar, 100, ]] -> [foo, 100, [bar, 600, ]]' | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      *                        ] | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      *                Example: | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      *                '[foo, 0, [bar, 10]] -> [foo, 10, [bar, 60]] | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      *                [foo, 10, [bar, 100]] -> [foo, 100, [bar, 600]]' | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     private function cleanAndFlatten(array $received): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |         return str_replace(', ]', ']', implode("\n", $received)); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  |