Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| FileStorageFactory | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| create | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\FileStorage; |
| 3 | |
| 4 | final class FileStorageFactory |
| 5 | { |
| 6 | /** |
| 7 | * @codeCoverageIgnore |
| 8 | */ |
| 9 | private function __construct() |
| 10 | { |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * @param array<string|int, mixed> $options |
| 15 | */ |
| 16 | public static function create(?array $options = null): ChainedFileStorage |
| 17 | { |
| 18 | $options ??= [['class' => InlineStorage::class]]; |
| 19 | $psrAwareStorages = []; |
| 20 | $resourceAwareStorages = []; |
| 21 | foreach ($options as $option) { |
| 22 | $instance = new ($option['class'])($option['options'] ?? null); |
| 23 | if ($instance instanceof PsrAwareStorageInterface) { |
| 24 | $psrAwareStorages[] = $instance; |
| 25 | } |
| 26 | if ($instance instanceof ResourceAwareStorageInterface) { |
| 27 | $resourceAwareStorages[] = $instance; |
| 28 | } |
| 29 | } |
| 30 | return new ChainedFileStorage($psrAwareStorages, $resourceAwareStorages); |
| 31 | } |
| 32 | } |