File tree Expand file tree Collapse file tree 4 files changed +60
-4
lines changed Expand file tree Collapse file tree 4 files changed +60
-4
lines changed Original file line number Diff line number Diff line change 25
25
use function is_array ;
26
26
use function is_dir ;
27
27
use function is_file ;
28
- use function is_string ;
29
28
use function preg_match ;
30
29
use function str_ends_with ;
31
30
use function str_ireplace ;
@@ -51,12 +50,12 @@ abstract class FileSystem
51
50
*/
52
51
public static function isAbsPath (string $ path ): bool
53
52
{
54
- if (!$ path || ! is_string ( $ path ) ) {
53
+ if (!$ path ) {
55
54
return false ;
56
55
}
57
56
58
57
if (str_starts_with ($ path , '/ ' ) || // linux/mac
59
- 1 === preg_match ('#^[a-z]:[\ /| \\\].+#i ' , $ path ) // windows
58
+ 1 === preg_match ('#^[a-z]:[/| \\\].+#i ' , $ path ) // windows
60
59
) {
61
60
return true ;
62
61
}
Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ class IniParser extends AbstractParser
39
39
* @param string $fileDir When the second param is true, this param is valid.
40
40
*
41
41
* @return array
42
- * @throws InvalidArgumentException
43
42
* @throws UnexpectedValueException
44
43
*/
45
44
protected static function doParse (
Original file line number Diff line number Diff line change 9
9
*/
10
10
class Path extends FileSystem
11
11
{
12
+ /**
13
+ * @param string $path
14
+ *
15
+ * @return bool
16
+ */
17
+ public static function isAbs (string $ path ): bool
18
+ {
19
+ return self ::isAbsPath ($ path );
20
+ }
12
21
22
+ /**
23
+ * @param string $path
24
+ *
25
+ * @return bool
26
+ */
27
+ public static function isAbsolute (string $ path ): bool
28
+ {
29
+ return self ::isAbsolutePath ($ path );
30
+ }
31
+
32
+ /**
33
+ * @param string $path
34
+ *
35
+ * @return string
36
+ */
37
+ public static function format (string $ path ): string
38
+ {
39
+ return self ::pathFormat ($ path );
40
+ }
13
41
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace Toolkit \FsUtilTest ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Toolkit \FsUtil \Path ;
7
+
8
+ /**
9
+ * class PathTest
10
+ *
11
+ * @author inhere
12
+ */
13
+ class PathTest extends TestCase
14
+ {
15
+ public function testPath_isAbs (): void
16
+ {
17
+ $ tests = [
18
+ '/tmp ' ,
19
+ 'C:/tmp ' ,
20
+ 'C: \\tmp ' ,
21
+ 'C:\tmp ' ,
22
+ "C: \\tmp " ,
23
+ ];
24
+
25
+ foreach ($ tests as $ case ) {
26
+ $ this ->assertTrue (Path::isAbs ($ case ));
27
+ $ this ->assertTrue (Path::isAbsolute ($ case ));
28
+ }
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments