Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| FlysystemReaderBackCompatTrait | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| has | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * `FilesystemReader` interface v3 introduced `::directoryExists()` and `::has()`. |
| 5 | * |
| 6 | * When this trait is used with your implementation of {@see League\Flysystem\FilesystemReader} and `league/flysystem` |
| 7 | * v3 is installed, the genuine parent methods are used, when v2 is installed the trait provides implementations. |
| 8 | * |
| 9 | * directoryExists, has |
| 10 | * @see https://github.com/thephpleague/flysystem/blob/2.x/src/FilesystemReader.php |
| 11 | * @see https://github.com/thephpleague/flysystem/blob/3.x/src/FilesystemReader.php |
| 12 | * |
| 13 | * @see https://github.com/thephpleague/flysystem/blob/3.x/src/Filesystem.php#L46-L51 |
| 14 | * |
| 15 | * `FilesystemAdapter` 3.x also introduced `::directoryExists()` so we re-use its compatibility trait here. |
| 16 | * @see FlysystemAdapterBackCompatTrait |
| 17 | */ |
| 18 | |
| 19 | namespace BrianHenryIE\Strauss\Helpers\Flysystem; |
| 20 | |
| 21 | /** |
| 22 | * @mixin FlysystemReaderBackCompatTraitInterface |
| 23 | * |
| 24 | * @method string normalizePath($location) |
| 25 | */ |
| 26 | trait FlysystemReaderBackCompatTrait |
| 27 | { |
| 28 | use FlysystemAdapterBackCompatTrait; |
| 29 | |
| 30 | /** |
| 31 | * @param string $location |
| 32 | * |
| 33 | * @return bool |
| 34 | * @throws \League\Flysystem\FilesystemException |
| 35 | */ |
| 36 | public function has(string $location): bool |
| 37 | { |
| 38 | /** |
| 39 | * @phpstan-ignore booleanAnd.leftAlwaysTrue |
| 40 | */ |
| 41 | if (get_parent_class(self::class) && method_exists(get_parent_class(self::class), 'has')) { |
| 42 | /** @phpstan-ignore staticMethod.notFound */ |
| 43 | return parent::has($location); |
| 44 | } |
| 45 | |
| 46 | // Can we assume ::fileExists and ::directoryExists will ::normalizePath anyway?! |
| 47 | return $this->fileExists($this->normalizePath($location)) || $this->directoryExists($this->normalizePath($location)); |
| 48 | } |
| 49 | } |