Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| ApieDirectory | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getChildren | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| getChild | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| childExists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Webdav\Dav; |
| 3 | |
| 4 | use Apie\ApieFileSystem\Virtual\VirtualFileInterface; |
| 5 | use Apie\ApieFileSystem\Virtual\VirtualFolderInterface; |
| 6 | use Sabre\DAV\Collection; |
| 7 | use Sabre\DAV\INode; |
| 8 | |
| 9 | class ApieDirectory extends Collection |
| 10 | { |
| 11 | public function __construct(private readonly VirtualFolderInterface $folder) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * @return INode[] |
| 17 | */ |
| 18 | public function getChildren(): array |
| 19 | { |
| 20 | $children = []; |
| 21 | foreach ($this->folder->getChildren() as $child) { |
| 22 | if ($child instanceof VirtualFolderInterface) { |
| 23 | $children[] = new ApieDirectory($child); |
| 24 | } else { |
| 25 | $children[] = new ApieFile($child); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | return $children; |
| 30 | } |
| 31 | |
| 32 | public function getChild($name): INode |
| 33 | { |
| 34 | $child = $this->folder->getChild($name); |
| 35 | if ($child instanceof VirtualFolderInterface) { |
| 36 | return new ApieDirectory($child); |
| 37 | } elseif ($child instanceof VirtualFileInterface) { |
| 38 | return new ApieFile($child); |
| 39 | } |
| 40 | throw new \Sabre\DAV\Exception\NotFound('File not found: ' . $name); |
| 41 | } |
| 42 | |
| 43 | public function childExists($name): bool |
| 44 | { |
| 45 | return null !== $this->folder->getChild($name); |
| 46 | } |
| 47 | |
| 48 | public function getName() |
| 49 | { |
| 50 | return $this->folder->getName(); |
| 51 | } |
| 52 | } |