AbstractSet   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 2
A offsetSet() 0 7 2
1
<?php
2
/**
3
 * This file is part of the ramsey/collection library
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright Copyright (c) Ben Ramsey <[email protected]>
9
 * @license http://opensource.org/licenses/MIT MIT
10
 * @link https://benramsey.com/projects/ramsey-collection/ Documentation
11
 * @link https://packagist.org/packages/ramsey/collection Packagist
12
 * @link https://github.com/ramsey/collection GitHub
13
 */
14
15
namespace Ramsey\Collection;
16
17
/**
18
 * This class contains the logic to make a Collection to not allow duplicated values,
19
 * to minimize the effort required to implement this specific type of Collection.
20
 */
21
abstract class AbstractSet extends AbstractCollection
22
{
23
    /**
24
     * Adds the specified element to this set if it is not already present (optional operation).
25
     *
26
     * @param mixed $element
27
     * @return bool true if this set did not already contain the specified element
28
     */
29
    public function add($element)
30
    {
31
        if ($this->contains($element)) {
32
            return false;
33
        }
34
        return parent::add($element);
35
    }
36
37
    public function offsetSet($offset, $value)
38
    {
39
        if ($this->contains($value)) {
40
            return;
41
        }
42
        parent::offsetSet($offset, $value);
43
    }
44
}
45