@@ -41,7 +41,7 @@ public function handle(GetKeys $getKeys): int
4141        }
4242
4343        $ envFilescollect ($ envFilesfilter (function  ($ fileuse  ($ ignoredFiles
44-             return  !  in_array (basename ($ file$ ignoredFiles
44+             return  !in_array (basename ($ file$ ignoredFiles
4545        })->toArray ();
4646
4747        if  (empty ($ envFiles
@@ -66,14 +66,22 @@ public function handle(GetKeys $getKeys): int
6666                    continue ;
6767                }
6868
69-                 [ $ keyMasterKey,  $ valueMaster ]  = explode ('= ' , $ keyMaster
70-                 [ $ keyEnvFileKey,  $ valueEnvFile ]  = explode ('= ' , $ keyEnvFile
69+                 $ keyMasterKey  = explode ('= ' , $ keyMaster[ 0 ] ;
70+                 $ keyEnvFileKey  = explode ('= ' , $ keyEnvFile[ 0 ] ;
7171
7272                if  ($ keyMasterKey$ keyEnvFileKey
7373                    continue ;
7474                }
7575
76-                 dump ($ keyMaster$ keyEnvFile
76+                 if  ($ this checkIfComment ($ keyMaster
77+                     $ this pushKeyOnLine ($ envFile$ line$ keyMaster
78+                     continue ;
79+                 }
80+ 
81+                 dump ($ keyMasterKey$ keyEnvFileKey
82+ 
83+                 // todo: find the key in the env file and move it to the correct line 
84+                 $ this moveKeyToLine ($ envFile$ keyMaster$ line
7785            }
7886        });
7987
@@ -84,4 +92,33 @@ private function getKeyFromFileOnLine(string $file, int $line): string
8492    {
8593        return  file ($ file$ line1 ];
8694    }
95+ 
96+     private  function  checkIfComment (string  $ linebool 
97+     {
98+         return  str_starts_with ($ line'# ' );
99+     }
100+ 
101+     private  function  pushKeyOnLine ($ file$ line$ keyvoid 
102+     {
103+         $ linesfile ($ file
104+         array_splice ($ lines$ line1 , 0 , $ key
105+ 
106+         file_put_contents ($ fileimplode ('' , $ lines
107+     }
108+ 
109+     private  function  moveKeyToLine (string  $ filestring  $ keyint  $ toLinevoid 
110+     {
111+         $ linesfile ($ file
112+         $ keyLinearray_search ($ key$ lines
113+ 
114+         if  ($ keyLinefalse ) {
115+             return ;
116+         }
117+ 
118+         unset($ lines$ keyLine
119+ 
120+         array_splice ($ lines$ toLine1 , 0 , $ key
121+ 
122+         file_put_contents ($ fileimplode ('' , $ lines
123+     }
87124}
0 commit comments