@@ -58,56 +58,16 @@ protected function fsSetRootDir(?string $path = NULL): static {
5858 * script was started from or current working directory.
5959 */
6060 protected function fsGetRootDir (): string {
61- if (isset ($ this ->fsRootDir )) {
62- return $ this ->fsRootDir ;
63- }
64-
65- if (isset ($ _SERVER ['PWD ' ]) && is_string ($ _SERVER ['PWD ' ]) && !empty ($ _SERVER ['PWD ' ])) {
66- return $ _SERVER ['PWD ' ];
67- }
68-
69- return (string ) getcwd ();
70- }
71-
72- /**
73- * Set current working directory.
74- *
75- * It is important to note that this should be called in pair with
76- * cwdRestore().
77- *
78- * @param string $dir
79- * Path to the current directory.
80- *
81- * @return static
82- * The called object.
83- */
84- protected function fsSetCwd (string $ dir ): static {
85- chdir ($ dir );
86- $ this ->fsOriginalCwdStack [] = $ dir ;
87-
88- return $ this ;
89- }
90-
91- /**
92- * Set current working directory to a previously saved path.
93- *
94- * It is important to note that this should be called in pair with cwdSet().
95- */
96- protected function fsCwdRestore (): void {
97- $ dir = array_shift ($ this ->fsOriginalCwdStack );
98- if ($ dir ) {
99- chdir ($ dir );
61+ if (!isset ($ this ->fsRootDir )) {
62+ if (isset ($ _SERVER ['PWD ' ]) && is_string ($ _SERVER ['PWD ' ]) && !empty ($ _SERVER ['PWD ' ])) {
63+ $ this ->fsRootDir = $ _SERVER ['PWD ' ];
64+ }
65+ else {
66+ $ this ->fsRootDir = (string ) getcwd ();
67+ }
10068 }
101- }
10269
103- /**
104- * Get current working directory.
105- *
106- * @return string
107- * Full path of current working directory.
108- */
109- protected function fsCwdGet (): string {
110- return (string ) getcwd ();
70+ return $ this ->fsRootDir ;
11171 }
11272
11373 /**
@@ -139,14 +99,14 @@ protected function fsIsCommandAvailable(string $command): bool {
13999 */
140100 protected function fsGetAbsolutePath (string $ file , ?string $ root = NULL ): string {
141101 if ($ this ->fs ->isAbsolutePath ($ file )) {
142- return $ this -> fsRealpath ($ file );
102+ return static :: fsRealpath ($ file );
143103 }
144104
145105 $ root = $ root ? $ root : $ this ->fsGetRootDir ();
146- $ root = $ this -> fsRealpath ($ root );
106+ $ root = static :: fsRealpath ($ root );
147107 $ file = $ root . DIRECTORY_SEPARATOR . $ file ;
148108
149- return $ this -> fsRealpath ($ file );
109+ return static :: fsRealpath ($ file );
150110 }
151111
152112 /**
@@ -192,16 +152,16 @@ protected function fsAssertPathsExist($paths, bool $strict = TRUE): bool {
192152 *
193153 * @see https://stackoverflow.com/a/29372360/712666
194154 */
195- protected function fsRealpath (string $ path ): string {
155+ protected static function fsRealpath (string $ path ): string {
196156 // Whether $path is unix or not.
197- $ unipath = $ path === '' || $ path [0 ] !== '/ ' ;
157+ $ is_unix_path = $ path === '' || $ path [0 ] !== '/ ' ;
198158 $ unc = str_starts_with ($ path , '\\\\' );
199159
200160 // Attempt to detect if path is relative in which case, add cwd.
201- if (!str_contains ($ path , ': ' ) && $ unipath && !$ unc ) {
161+ if (!str_contains ($ path , ': ' ) && $ is_unix_path && !$ unc ) {
202162 $ path = getcwd () . DIRECTORY_SEPARATOR . $ path ;
203163 if ($ path [0 ] === '/ ' ) {
204- $ unipath = FALSE ;
164+ $ is_unix_path = FALSE ;
205165 }
206166 }
207167
@@ -225,21 +185,21 @@ protected function fsRealpath(string $path): string {
225185 }
226186
227187 $ path = implode (DIRECTORY_SEPARATOR , $ absolutes );
188+ // Put initial separator that could have been lost.
189+ $ path = $ is_unix_path ? $ path : '/ ' . $ path ;
190+ $ path = $ unc ? '\\\\' . $ path : $ path ;
228191
229192 // Resolve any symlinks.
230- if (function_exists ('readlink ' ) && file_exists ($ path ) && linkinfo ($ path ) > 0 ) {
193+ if (function_exists ('readlink ' ) && file_exists ($ path ) && is_link ($ path ) > 0 ) {
231194 $ path = readlink ($ path );
232195
233196 if (!$ path ) {
197+ // @codeCoverageIgnoreStart
234198 throw new \Exception (sprintf ('Could not resolve symlink for path: %s ' , $ path ));
199+ // @codeCoverageIgnoreEnd
235200 }
236201 }
237202
238- // Put initial separator that could have been lost.
239- $ path = $ unipath ? $ path : '/ ' . $ path ;
240-
241- $ path = $ unc ? '\\\\' . $ path : $ path ;
242-
243203 if (str_starts_with ($ path , sys_get_temp_dir ())) {
244204 $ tmp_realpath = realpath (sys_get_temp_dir ());
245205 if ($ tmp_realpath ) {
0 commit comments