@@ -45,9 +45,9 @@ protected function move(string $filename): void
4545 $ content = $ this ->replaceClassName ($ content );
4646 $ content = $ this ->replaceDeclareStrictType ($ content );
4747 $ content = $ this ->replaceWithInvoke ($ content );
48+ $ content = $ this ->replaceProperties ($ content );
4849
4950 $ this ->store ($ filename , $ content );
50- $ this ->delete ($ filename );
5151 }
5252
5353 protected function clean (): void
@@ -57,19 +57,19 @@ protected function clean(): void
5757 ));
5858 }
5959
60- protected function open (string $ path ): string
60+ protected function open (string $ filename ): string
6161 {
62- return file_get_contents (base_path ('database/actions/ ' . $ path ));
62+ return file_get_contents (base_path ('database/actions/ ' . $ filename ));
6363 }
6464
65- protected function store (string $ path , string $ content ): void
65+ protected function store (string $ filename , string $ content ): void
6666 {
67- file_put_contents ($ this ->config ->path ($ path ), $ content );
67+ File:: store ($ this ->config ->path ($ filename ), $ content );
6868 }
6969
70- protected function delete (string $ path ): void
70+ protected function delete (string $ filename ): void
7171 {
72- File::ensureDelete ($ this -> config -> path ( $ path ) );
72+ File::ensureDelete ($ filename );
7373 }
7474
7575 protected function replaceNamespace (string $ content ): string
@@ -83,8 +83,9 @@ protected function replaceNamespace(string $content): string
8383 protected function replaceClassName (string $ content ): string
8484 {
8585 return Str::of ($ content )
86- ->pregReplace ('/^([ final\s|class]+ .+extends\sAction)$ / ' , 'return new class () extends Action ' )
86+ ->pregReplace ('/((?:return\s+new\s+class\s*\(?\s*\)?| final\s+class |class)\s* .+extends\s+Action) / ' , 'return new class () extends Action ' )
8787 ->trim ()
88+ ->trim ('; ' )
8889 ->append ('; ' )
8990 ->append (PHP_EOL )
9091 ->toString ();
@@ -106,6 +107,18 @@ protected function replaceWithInvoke(string $content): string
106107 })->toString ();
107108 }
108109
110+ protected function replaceProperties (string $ content ): string
111+ {
112+ return Str::of ($ content )
113+ ->pregReplace ('/protected\s+\$once/ ' , 'protected bool $once ' )
114+ ->pregReplace ('/protected\s+\$transactions/ ' , 'protected bool $transactions ' )
115+ ->pregReplace ('/protected\s+\$transaction_attempts/ ' , 'protected int $transactionAttempts ' )
116+ ->pregReplace ('/protected\s+\$environment/ ' , 'protected string|array|null $environment ' )
117+ ->pregReplace ('/protected\s+\$except_environment/ ' , 'protected string|array|null $exceptEnvironment ' )
118+ ->pregReplace ('/protected\s+\$before/ ' , 'protected bool $before ' )
119+ ->toString ();
120+ }
121+
109122 protected function moveConfig (): void
110123 {
111124 $ this ->notification ->task ('Moving config file ' , function () {
@@ -126,7 +139,7 @@ protected function moveConfig(): void
126139
127140 protected function getOldFiles (): array
128141 {
129- return $ this ->getFiles (path: database_path ('actions ' ));
142+ return $ this ->getFiles (path: database_path ('actions ' ), realpath: true );
130143 }
131144
132145 protected function alreadyUpgraded (): bool
0 commit comments