| Total Complexity | 6 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | /*final*/ class LazyChoice implements ChoiceInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * The lazy callback with returns choices |
||
| 17 | * |
||
| 18 | * @var callable():(T[]|ChoiceInterface<T>) |
||
| 19 | */ |
||
| 20 | private $resolver; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The choice object |
||
| 24 | * |
||
| 25 | * @var ChoiceInterface<T>|null |
||
| 26 | */ |
||
| 27 | private $choices; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * LazyChoice constructor. |
||
| 31 | * |
||
| 32 | * @param callable():(T[]|ChoiceInterface<T>) $resolver |
||
| 33 | */ |
||
| 34 | 2 | public function __construct(callable $resolver) |
|
| 35 | { |
||
| 36 | 2 | $this->resolver = $resolver; |
|
| 37 | 2 | } |
|
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | 2 | public function values(): array |
|
| 43 | { |
||
| 44 | 2 | return $this->build()->values(); |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | 1 | public function view(?callable $configuration = null): array |
|
| 51 | { |
||
| 52 | 1 | return $this->build()->view($configuration); |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Resolve the lazy choice list |
||
| 57 | */ |
||
| 58 | 2 | private function build(): ChoiceInterface |
|
| 71 | } |
||
| 72 | } |
||
| 73 |