Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
69.23% |
9 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FlysystemBackCompatTrait | |
69.23% |
9 / 13 |
|
0.00% |
0 / 2 |
8.43 | |
0.00% |
0 / 1 |
| directoryExists | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
4.02 | |||
| has | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BrianHenryIE\Strauss\Helpers; |
| 4 | |
| 5 | use Elazar\Flystream\StripProtocolPathNormalizer; |
| 6 | use League\Flysystem\FileAttributes; |
| 7 | use League\Flysystem\WhitespacePathNormalizer; |
| 8 | |
| 9 | /** |
| 10 | * @see FlysystemBackCompatInterface |
| 11 | */ |
| 12 | trait FlysystemBackCompatTrait |
| 13 | { |
| 14 | |
| 15 | // Some version of Flysystem has: |
| 16 | // directoryExists |
| 17 | public function directoryExists(string $location): bool |
| 18 | { |
| 19 | if (method_exists($this->flysystem, 'directoryExists')) { |
| 20 | return $this->flysystem->directoryExists($location); |
| 21 | } |
| 22 | |
| 23 | $normalizer = new WhitespacePathNormalizer(); |
| 24 | $normalizer = new StripProtocolPathNormalizer(['mem'], $normalizer); |
| 25 | $location = $normalizer->normalizePath($location); |
| 26 | |
| 27 | $parentDirectoryContents = $this->listContents(dirname($location)); |
| 28 | /** @var FileAttributes $entry */ |
| 29 | foreach ($parentDirectoryContents as $entry) { |
| 30 | if ($entry->path() == $location) { |
| 31 | return $entry->isDir(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | // Some version of Flysystem has: |
| 39 | // has |
| 40 | public function has(string $location): bool |
| 41 | { |
| 42 | if (method_exists($this->flysystem, 'has')) { |
| 43 | return $this->flysystem->has($location); |
| 44 | } |
| 45 | return $this->fileExists($location) || $this->directoryExists($location); |
| 46 | } |
| 47 | } |