Completed
Push — master ( dc0c42...1f841e )
by Carlos C
11:21
created

Collection::getElementType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace GenericCollections;
2
3
use GenericCollections\Abstracts\AbstractCollection;
4
use GenericCollections\Utils\TypeProperty;
5
6
/**
7
 * Generic collection implementation
8
 *
9
 * The elements comparison can be defined ad identical or equal,
10
 * if identical searchs match with '==='
11
 * if equal searchs match with '=='
12
 *
13
 * @package GenericCollections
14
 */
15
class Collection extends AbstractCollection
16
{
17
    /**
18
     * @var TypeProperty
19
     */
20
    private $elementType;
21
22
    /**
23
     * Comparison types
24
     * @var bool
25
     */
26
    private $comparisonIdentical;
27
28
    /**
29
     * Generic collection
30
     *
31
     * example: `new Collection(Foo::class, [new Foo(), new Foo()]`
32
     *
33
     * @param string $elementType
34
     * @param array $elements
35
     * @param bool $comparisonIdentical
36
     */
37
    public function __construct($elementType, array $elements = [], $comparisonIdentical = true)
38
    {
39
        $this->elementType = new TypeProperty($elementType);
40
        $this->comparisonIdentical = (bool) $comparisonIdentical;
41
        $this->addAll($elements);
42
    }
43
44
    // implements CollectionInterface::getElementType : string
45
    public function getElementType()
46
    {
47
        return (string) $this->elementType;
48
    }
49
50
    // implements CollectionInterface::getElementType : bool
51
    public function comparisonMethodIsIdentical()
52
    {
53
        return $this->comparisonIdentical;
54
    }
55
}
56