11<?php
22
3+ declare (strict_types=1 );
4+
5+ /**
6+ * This file is part of fast-forward/dev-tools.
7+ *
8+ * This source file is subject to the license bundled
9+ * with this source code in the file LICENSE.
10+ *
11+ * @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
12+ * @license https://opensource.org/licenses/MIT MIT License
13+ *
14+ * @see https://github.com/php-fast-forward/dev-tools
15+ * @see https://github.com/php-fast-forward
16+ * @see https://datatracker.ietf.org/doc/html/rfc2119
17+ */
18+
319namespace FastForward \DevTools \Filesystem ;
420
521use Override ;
622use function Safe \getcwd ;
723use Symfony \Component \Filesystem \Filesystem as SymfonyFilesystem ;
824use Symfony \Component \Filesystem \Path ;
925
26+ /**
27+ * Concrete implementation of the standard filesystem interface.
28+ *
29+ * This class wraps over the Symfony Filesystem component, automatically
30+ * converting provided paths to absolute representations when a base path is supplied or
31+ * dynamically inferred from the generic working directory.
32+ */
1033final class Filesystem extends SymfonyFilesystem implements FilesystemInterface
1134{
1235 /**
13- * @param string|iterable $files
14- * @param string|null $basePath
36+ * Checks whether a file or directory exists.
1537 *
16- * @return bool
38+ * @param iterable<string>|string $files the file(s) or directory(ies) to check
39+ * @param string|null $basePath the base path used to resolve relative paths
40+ *
41+ * @return bool true if the path exists, false otherwise
1742 */
1843 #[Override]
1944 public function exists (string |iterable $ files , ?string $ basePath = null ): bool
@@ -22,10 +47,12 @@ public function exists(string|iterable $files, ?string $basePath = null): bool
2247 }
2348
2449 /**
25- * @param string $filename
26- * @param string|null $path
50+ * Reads the entire content of a file.
51+ *
52+ * @param string $filename the target filename to read
53+ * @param string|null $path the optional base path to resolve the filename against
2754 *
28- * @return string
55+ * @return string the content of the file
2956 */
3057 #[Override]
3158 public function readFile (string $ filename , ?string $ path = null ): string
@@ -34,23 +61,25 @@ public function readFile(string $filename, ?string $path = null): string
3461 }
3562
3663 /**
37- * @param string $filename
38- * @param mixed $content
39- * @param string|null $path
64+ * Writes content to a file, overriding it if it already exists.
4065 *
41- * @return void
66+ * @param string $filename the filename to write to
67+ * @param mixed $content the content to write
68+ * @param string|null $path the optional base path to resolve the filename against
4269 */
4370 #[Override]
44- public function dumpFile (string $ filename , $ content , ?string $ path = null ): void
71+ public function dumpFile (string $ filename , mixed $ content , ?string $ path = null ): void
4572 {
4673 parent ::dumpFile ($ this ->getAbsolutePath ($ filename , $ path ), $ content );
4774 }
4875
4976 /**
50- * @param string|iterable $files
51- * @param string|null $basePath
77+ * Resolves a path or iterable of paths into their absolute path representation.
5278 *
53- * @return string|iterable
79+ * @param iterable<string>|string $files the path(s) to resolve
80+ * @param string|null $basePath the base path for relative path resolution
81+ *
82+ * @return iterable<string>|string the resolved absolute path(s)
5483 */
5584 public function getAbsolutePath (string |iterable $ files , ?string $ basePath = null ): string |iterable
5685 {
@@ -68,11 +97,11 @@ public function getAbsolutePath(string|iterable $files, ?string $basePath = null
6897 }
6998
7099 /**
71- * @param string|iterable $dirs
72- * @param int $mode
73- * @param string|null $basePath
100+ * Creates a directory recursively.
74101 *
75- * @return void
102+ * @param iterable<string>|string $dirs the directory path(s) to create
103+ * @param int $mode the permissions mode (defaults to 0777)
104+ * @param string|null $basePath the base path for relative path resolution
76105 */
77106 #[Override]
78107 public function mkdir (string |iterable $ dirs , int $ mode = 0777 , ?string $ basePath = null ): void
@@ -81,10 +110,12 @@ public function mkdir(string|iterable $dirs, int $mode = 0777, ?string $basePath
81110 }
82111
83112 /**
84- * @param string $path
85- * @param string|null $basePath
113+ * Computes the relative path from the base path to the target path.
114+ *
115+ * @param string $path the target absolute or relative path
116+ * @param string|null $basePath the origin point; defaults to the current working directory
86117 *
87- * @return string
118+ * @return string the computed relative path
88119 */
89120 #[Override]
90121 public function makePathRelative (string $ path , ?string $ basePath = null ): string
@@ -96,21 +127,25 @@ public function makePathRelative(string $path, ?string $basePath = null): string
96127 }
97128
98129 /**
99- * @param string $path
100- * @param string $suffix
130+ * Returns the trailing name component of a path.
101131 *
102- * @return string
132+ * @param string $path the path to process
133+ * @param string $suffix an optional suffix to strip from the returned basename
134+ *
135+ * @return string the base name of the given path
103136 */
104137 public function basename (string $ path , string $ suffix = '' ): string
105138 {
106139 return \basename ($ path , $ suffix );
107140 }
108141
109142 /**
110- * @param string $path
111- * @param int $levels
143+ * Returns a parent directory's path.
144+ *
145+ * @param string $path the path to evaluate
146+ * @param int $levels the number of parent directories to go up
112147 *
113- * @return string
148+ * @return string the parent path name
114149 */
115150 public function dirname (string $ path , int $ levels = 1 ): string
116151 {
0 commit comments