Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| LocalStorage | |
100.00% |
25 / 25 |
|
100.00% |
9 / 9 |
20 | |
100.00% |
1 / 1 |
| getClassType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
4 | |||
| put | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| get | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| list | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| create | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| set | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| append | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| prepend | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| extension | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\System\File\Local |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\System\File\Local; |
| 16 | |
| 17 | use phpOMS\System\File\PathException; |
| 18 | use phpOMS\System\File\StorageAbstract; |
| 19 | |
| 20 | /** |
| 21 | * Filesystem class. |
| 22 | * |
| 23 | * Performing operations on the file system |
| 24 | * |
| 25 | * @package phpOMS\System\File\Local |
| 26 | * @license OMS License 2.0 |
| 27 | * @link https://jingga.app |
| 28 | * @since 1.0.0 |
| 29 | */ |
| 30 | class LocalStorage extends StorageAbstract |
| 31 | { |
| 32 | /** |
| 33 | * {@inheritdoc} |
| 34 | */ |
| 35 | protected static function getClassType(string $path) : string |
| 36 | { |
| 37 | return \is_dir($path) || (!\is_file($path) && \stripos($path, '.') === false) ? Directory::class : File::class; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * {@inheritdoc} |
| 42 | * |
| 43 | * @throws PathException |
| 44 | */ |
| 45 | public static function put(string $path, string $content, int $mode = 0) : bool |
| 46 | { |
| 47 | if (\is_dir($path)) { |
| 48 | throw new PathException($path); |
| 49 | } |
| 50 | |
| 51 | return File::put($path, $content, $mode); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | * |
| 57 | * @throws PathException |
| 58 | */ |
| 59 | public static function get(string $path) : string |
| 60 | { |
| 61 | if (\is_dir($path)) { |
| 62 | throw new PathException($path); |
| 63 | } |
| 64 | |
| 65 | return File::get($path); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * {@inheritdoc} |
| 70 | * |
| 71 | * @throws PathException |
| 72 | */ |
| 73 | public static function list(string $path, string $filter = '*', bool $recursive = false) : array |
| 74 | { |
| 75 | if (\is_file($path)) { |
| 76 | throw new PathException($path); |
| 77 | } |
| 78 | |
| 79 | return Directory::list($path, $filter, $recursive); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * {@inheritdoc} |
| 84 | */ |
| 85 | public static function create(string $path) : bool |
| 86 | { |
| 87 | return \stripos($path, '.') === false |
| 88 | ? Directory::create($path, 0755, true) |
| 89 | : File::create($path); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * {@inheritdoc} |
| 94 | * |
| 95 | * @throws PathException |
| 96 | */ |
| 97 | public static function set(string $path, string $content) : bool |
| 98 | { |
| 99 | if (\is_dir($path)) { |
| 100 | throw new PathException($path); |
| 101 | } |
| 102 | |
| 103 | return File::set($path, $content); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * {@inheritdoc} |
| 108 | * |
| 109 | * @throws PathException |
| 110 | */ |
| 111 | public static function append(string $path, string $content) : bool |
| 112 | { |
| 113 | if (\is_dir($path)) { |
| 114 | throw new PathException($path); |
| 115 | } |
| 116 | |
| 117 | return File::append($path, $content); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * {@inheritdoc} |
| 122 | * |
| 123 | * @throws PathException |
| 124 | */ |
| 125 | public static function prepend(string $path, string $content) : bool |
| 126 | { |
| 127 | if (\is_dir($path)) { |
| 128 | throw new PathException($path); |
| 129 | } |
| 130 | |
| 131 | return File::prepend($path, $content); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * {@inheritdoc} |
| 136 | * |
| 137 | * @throws PathException |
| 138 | */ |
| 139 | public static function extension(string $path) : string |
| 140 | { |
| 141 | if (\is_dir($path)) { |
| 142 | throw new PathException($path); |
| 143 | } |
| 144 | |
| 145 | return File::extension($path); |
| 146 | } |
| 147 | } |