| Total Complexity | 12 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 73.08% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class CustomResourcesExport |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array<CustomResourcesExport> |
||
| 11 | */ |
||
| 12 | public static array $exports = []; |
||
| 13 | |||
| 14 | 10 | public static function use(string|CustomExport|array $export): static |
|
| 15 | { |
||
| 16 | 10 | if (is_array($export)) { |
|
|
|
|||
| 17 | foreach ($export as $exportItem) { |
||
| 18 | static::use($exportItem); |
||
| 19 | } |
||
| 20 | |||
| 21 | return new static; |
||
| 22 | } |
||
| 23 | |||
| 24 | 10 | if (!is_string($export)) { |
|
| 25 | $export = $export::class; |
||
| 26 | } |
||
| 27 | |||
| 28 | 10 | if (!is_subclass_of($export, CustomExport::class)) { |
|
| 29 | throw new \Exception('Custom export should be subclass of ' . CustomExport::class); |
||
| 30 | } |
||
| 31 | |||
| 32 | 10 | static::$exports[] = $export; |
|
| 33 | |||
| 34 | 10 | return new static; |
|
| 35 | } |
||
| 36 | |||
| 37 | 3 | public static function options(): array |
|
| 38 | { |
||
| 39 | 3 | $exportsList = []; |
|
| 40 | 3 | $exports = static::$exports; |
|
| 41 | 3 | if(!empty($exports)) { |
|
| 42 | /** @var CustomExport $export */ |
||
| 43 | 3 | foreach ($exports as $export) { |
|
| 44 | 3 | $exportsList[$export::key()] = $export::name(); |
|
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | 3 | return $exportsList; |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | public static function findByKey(string $key): ?CustomExport |
|
| 66 | } |
||
| 67 | } |
||
| 68 |