1 | <?php |
||
16 | final class Folder |
||
17 | { |
||
18 | /** @var Filesystem */ |
||
19 | private $fs; |
||
|
|||
20 | /** @var FilesystemPath */ |
||
21 | private $folder; |
||
22 | |||
23 | /** |
||
24 | * @param string $folderPath |
||
25 | */ |
||
26 | 36 | public function __construct($folderPath) |
|
27 | { |
||
28 | 36 | $this->fs = new Filesystem(); |
|
29 | 36 | $this->folder = new FilesystemPath($folderPath); |
|
30 | |||
31 | 36 | if (!$this->folder->isDir()) |
|
32 | { |
||
33 | throw new FileNotFoundException(sprintf('The folder could not be found: %s', $folderPath)); |
||
34 | } |
||
35 | 36 | } |
|
36 | |||
37 | public function __toString() |
||
41 | |||
42 | /** |
||
43 | * Set a base folder that will be prefixed before all file writes and copies. |
||
44 | * |
||
45 | * @param string $folderName |
||
46 | * |
||
47 | * @since 0.1.0 |
||
48 | */ |
||
49 | public function setTargetDirectory($folderName) |
||
50 | { |
||
51 | if ($folderName === null || empty($folderName)) |
||
52 | { |
||
53 | return; |
||
54 | } |
||
55 | |||
56 | $this->folder->appendToPath($folderName); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Copy a file from an absolute file to a path relative to the Folder's location. |
||
61 | * |
||
62 | * @param string $absolutePath The absolute path of the file |
||
63 | * @param string $targetPath The relative file path to the Folder's location |
||
64 | * |
||
65 | * @since 0.1.0 |
||
66 | */ |
||
67 | public function copyFile($absolutePath, $targetPath) |
||
73 | |||
74 | /** |
||
75 | * Write a file with the specified content. |
||
76 | * |
||
77 | * @param string $relativePath The file path relative to this Folder's location |
||
78 | * @param string $content The content that will be written to the file |
||
79 | * |
||
80 | * @since 0.1.0 |
||
81 | * |
||
82 | * @return File |
||
83 | */ |
||
84 | 36 | public function writeFile($relativePath, $content) |
|
102 | } |
||
103 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.