Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TreeDefinitions
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 makeDefinitions
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace pvc\struct\tree\di;
6
7use League\Container\Definition\Definition;
8use League\Container\Definition\DefinitionInterface;
9use pvc\interfaces\struct\payload\HasPayloadInterface;
10use pvc\interfaces\validator\ValTesterInterface;
11use pvc\struct\collection\Collection;
12use pvc\struct\collection\CollectionFactory;
13use pvc\struct\collection\CollectionIndexed;
14use pvc\struct\collection\CollectionIndexedFactory;
15use pvc\struct\tree\node\TreenodeCollectionFactory;
16use pvc\struct\tree\node\TreenodeFactory;
17use pvc\struct\tree\tree\Tree;
18use pvc\struct\tree\tree\TreeOrdered;
19
20/**
21 * @template PayloadType of HasPayloadInterface
22 */
23class 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}