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

Map   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 2
cbo 3
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getKeyType() 0 4 1
A getValueType() 0 4 1
A comparisonMethodIsIdentical() 0 4 1
1
<?php namespace GenericCollections;
2
3
use GenericCollections\Abstracts\AbstractMap;
4
use GenericCollections\Utils\TypeProperty;
5
use GenericCollections\Utils\TypeKeyProperty;
6
7
class Map extends AbstractMap
8
{
9
    /**
10
     * @var TypeProperty
11
     */
12
    private $valueType;
13
14
    /**
15
     * @var TypeKeyProperty
16
     */
17
    private $keyType;
18
19
    /**
20
     * Comparison types
21
     * @var bool
22
     */
23
    private $comparisonIdentical;
24
25
    /**
26
     * Generic map
27
     *
28
     * example:
29
     * ```php
30
     * new Map('string', Foo::class, [
31
     *     'one' => new Foo(),
32
     *     'two' => new Foo(),
33
     * ];
34
     * ```
35
     *
36
     * @param string $keyType
37
     * @param string $valueType
38
     * @param array $values
39
     * @param bool $comparisonIdentical
40
     */
41
    public function __construct($keyType, $valueType, array $values = [], $comparisonIdentical = true)
42
    {
43
        $this->keyType = new TypeKeyProperty($keyType);
44
        $this->valueType = new TypeProperty($valueType);
45
        $this->comparisonIdentical = (bool) $comparisonIdentical;
46
        $this->putAll($values);
47
    }
48
49
    // implements MapInterface::getKeyType : bool
50
    public function getKeyType()
51
    {
52
        return (string) $this->keyType;
53
    }
54
55
    // implements MapInterface::getValueType : bool
56
    public function getValueType()
57
    {
58
        return (string) $this->valueType;
59
    }
60
61
    // implements MapInterface::comparisonMethodIsIdentical : bool
62
    public function comparisonMethodIsIdentical()
63
    {
64
        return $this->comparisonIdentical;
65
    }
66
}
67