Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TreenodeFactory
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 makeCollection
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @author: Doug Wilbourne (dougwilbourne@gmail.com)
5 */
6declare(strict_types=1);
7
8namespace pvc\struct\tree\node;
9
10use pvc\interfaces\struct\collection\CollectionFactoryInterface;
11use pvc\interfaces\struct\collection\CollectionInterface;
12use pvc\interfaces\struct\tree\node\TreenodeFactoryInterface;
13use pvc\interfaces\struct\tree\node\TreenodeInterface;
14use pvc\interfaces\struct\tree\tree\TreeInterface;
15
16/**
17 * Class TreenodeFactory
18 *
19 * Tree and TreenodeFactory are mutually dependent.  The constructors are set up so that you create
20 * TreenodeFactory first without its tree dependency, use TreenodeFactory in the construction of a new tree,
21 * and then go back and set the tree property in TreenodeFactory.  Tree factory does all this in the method
22 * makeTree.
23 *
24 * @template TreenodeType of TreenodeInterface
25 * @template CollectionType of CollectionInterface
26 * @template TreeType of TreeInterface
27 * @implements TreenodeFactoryInterface<TreenodeType, CollectionType>
28 */
29abstract class TreenodeFactory implements TreenodeFactoryInterface
30{
31    /**
32     * @param  CollectionFactoryInterface<TreenodeType, CollectionType>  $collectionFactory
33     */
34    public function __construct(
35        protected CollectionFactoryInterface $collectionFactory,
36    ) {
37    }
38
39    /**
40     * @return CollectionType
41     */
42    public function makeCollection(): CollectionInterface
43    {
44        /** @var array<TreenodeType> $array */
45        $array = [];
46        /** @var CollectionType $collection */
47        $collection = $this->collectionFactory->makeCollection($array);
48        return $collection;
49    }
50}