22
33namespace LaravelReady \EnvProfiles \Services ;
44
5- use Illuminate \Support \Facades \File ;
65use Illuminate \Support \Facades \Artisan ;
6+ use Illuminate \Support \Facades \File ;
77
88class EnvFileService
99{
@@ -16,7 +16,7 @@ public function __construct()
1616
1717 public function read ()
1818 {
19- if (!File::exists ($ this ->envPath )) {
19+ if (! File::exists ($ this ->envPath )) {
2020 return '' ;
2121 }
2222
@@ -26,36 +26,36 @@ public function read()
2626 public function write ($ content )
2727 {
2828 $ this ->backup ();
29-
29+
3030 File::put ($ this ->envPath , $ content );
31-
31+
3232 $ this ->clearConfigCache ();
3333 }
3434
3535 public function backup ()
3636 {
37- if (!File::exists ($ this ->envPath ) || !config ('env-profile-manager.features.backups ' , true )) {
37+ if (! File::exists ($ this ->envPath ) || ! config ('env-profile-manager.features.backups ' , true )) {
3838 return ;
3939 }
4040
4141 $ backupPath = $ this ->envPath . '.backup. ' . date ('YmdHis ' );
4242 File::copy ($ this ->envPath , $ backupPath );
43-
43+
4444 $ this ->cleanOldBackups ();
4545 }
4646
4747 protected function cleanOldBackups ()
4848 {
4949 $ backupFiles = File::glob (base_path ('.env.backup.* ' ));
5050 $ maxBackups = config ('env-profile-manager.max_backups ' , 10 );
51-
51+
5252 if (count ($ backupFiles ) > $ maxBackups ) {
5353 usort ($ backupFiles , function ($ a , $ b ) {
5454 return filemtime ($ a ) - filemtime ($ b );
5555 });
56-
56+
5757 $ filesToDelete = array_slice ($ backupFiles , 0 , count ($ backupFiles ) - $ maxBackups );
58-
58+
5959 foreach ($ filesToDelete as $ file ) {
6060 File::delete ($ file );
6161 }
@@ -64,7 +64,7 @@ protected function cleanOldBackups()
6464
6565 protected function clearConfigCache ()
6666 {
67- if (app ()->runningInConsole () && !app ()->runningUnitTests ()) {
67+ if (app ()->runningInConsole () && ! app ()->runningUnitTests ()) {
6868 Artisan::call ('config:clear ' );
6969 }
7070 }
@@ -76,7 +76,7 @@ public function parseEnv($content)
7676
7777 foreach ($ lines as $ line ) {
7878 $ line = trim ($ line );
79-
79+
8080 if (empty ($ line ) || strpos ($ line , '# ' ) === 0 ) {
8181 continue ;
8282 }
@@ -93,15 +93,15 @@ public function parseEnv($content)
9393 protected function parseValue ($ value )
9494 {
9595 $ value = trim ($ value );
96-
96+
9797 if (preg_match ('/^"(.*)"\s*$/ ' , $ value , $ matches )) {
9898 return $ matches [1 ];
9999 }
100-
100+
101101 if (preg_match ('/^ \'(.*) \'\s*$/ ' , $ value , $ matches )) {
102102 return $ matches [1 ];
103103 }
104-
104+
105105 return $ value ;
106106 }
107- }
107+ }
0 commit comments