Set   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getType() 0 4 1
1
<?php
2
3
namespace Ramsey\Collection;
4
5
/**
6
 * A Set is a Collection that contains no duplicate elements.
7
 *
8
 * Great care must be exercised if mutable objects are used as set elements.
9
 * The behavior of a Set is not specified if the value of an object is changed in a manner
10
 * that affects equals comparisons while the object is an element in the set.
11
 *
12
 * Example usage:
13
 *
14
 * ``` php
15
 * $foo = new \My\Foo();
16
 * $set = new Set(\My\Foo::class);
17
 *
18
 * $set->add($foo); // returns TRUE, the element don't exists
19
 * $set->add($foo); // returns FALSE, the element already exists
20
 *
21
 * $bar = new \My\Foo();
22
 * $set->add($bar); // returns TRUE, $bar !== $foo
23
 * ```
24
 */
25
class Set extends AbstractSet
26
{
27
    /**
28
     * The type of elements stored in this set
29
     *
30
     * A set's type is immutable. For this reason, this property is private
31
     *
32
     * @var string
33
     */
34
    private $setType;
35
36
    /**
37
     * Constructs a Set object of the specified type,
38
     * optionally with the specified data
39
     *
40
     * @param string $setType
41
     * @param array $data
42
     */
43
    public function __construct($setType, array $data = [])
44
    {
45
        $this->setType = $setType;
46
        parent::__construct($data);
47
    }
48
49
    /**
50
     * Returns the type associated with this set
51
     *
52
     * @return string
53
     */
54
    public function getType()
55
    {
56
        return $this->setType;
57
    }
58
}
59