Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
TreeDefinitions | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
makeDefinitions | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace pvc\struct\tree\di; |
6 | |
7 | use League\Container\Definition\Definition; |
8 | use League\Container\Definition\DefinitionInterface; |
9 | use pvc\interfaces\struct\payload\HasPayloadInterface; |
10 | use pvc\interfaces\validator\ValTesterInterface; |
11 | use pvc\struct\collection\Collection; |
12 | use pvc\struct\collection\CollectionFactory; |
13 | use pvc\struct\collection\CollectionIndexed; |
14 | use pvc\struct\collection\CollectionIndexedFactory; |
15 | use pvc\struct\tree\node\TreenodeCollectionFactory; |
16 | use pvc\struct\tree\node\TreenodeFactory; |
17 | use pvc\struct\tree\tree\Tree; |
18 | use pvc\struct\tree\tree\TreeOrdered; |
19 | |
20 | /** |
21 | * @template PayloadType of HasPayloadInterface |
22 | */ |
23 | class TreeDefinitions |
24 | { |
25 | /** |
26 | * @param ValTesterInterface<PayloadType>|null $payloadTester |
27 | * @return array<int, DefinitionInterface> |
28 | */ |
29 | public static function makeDefinitions(?ValTesterInterface $payloadTester): array |
30 | { |
31 | return [ |
32 | |
33 | /** |
34 | * objects necessary to make a plain (unordered) tree |
35 | */ |
36 | (new Definition(Collection::class)), |
37 | (new Definition(CollectionFactory::class)), |
38 | (new Definition('TreenodeCollectionFactoryUnordered', TreenodeCollectionFactory::class)) |
39 | ->addArgument(CollectionFactory::class), |
40 | (new Definition('TreenodeFactoryUnordered', TreenodeFactory::class)) |
41 | ->addArgument('TreenodeCollectionFactoryUnordered') |
42 | ->addArgument($payloadTester), |
43 | (new Definition(Tree::class))->addArgument('TreenodeFactoryUnordered'), |
44 | |
45 | /** |
46 | * objects necessary to make an ordered tree |
47 | */ |
48 | (new Definition(CollectionIndexed::class)), |
49 | (new Definition(CollectionIndexedFactory::class)), |
50 | (new Definition('TreenodeCollectionFactoryOrdered', TreenodeCollectionFactory::class)) |
51 | ->addArgument(CollectionIndexedFactory::class), |
52 | (new Definition('TreenodeFactoryOrdered', TreenodeFactory::class)) |
53 | ->addArgument('TreenodeCollectionFactoryOrdered') |
54 | ->addArgument($payloadTester), |
55 | |
56 | (new Definition(TreeOrdered::class))->addArgument('TreenodeFactoryOrdered'), |
57 | ]; |
58 | } |
59 | } |