AbstractSet   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A getIterator() 0 4 1
A clear() 0 4 1
A isEmpty() 0 4 1
A count() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the bisarca/graph package.
5
 *
6
 * (c) Emanuele Minotto <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bisarca\Graph;
13
14
use ArrayIterator;
15
use Bisarca\Graph\Attribute\AttributeAwareInterface;
16
use Bisarca\Graph\Attribute\AttributeAwareTrait;
17
use Countable;
18
use IteratorAggregate;
19
use Traversable;
20
21
/**
22
 * Abstract set of utilities for internal sets.
23
 */
24
abstract class AbstractSet implements AttributeAwareInterface, Countable, IteratorAggregate
25
{
26
    use AttributeAwareTrait;
27
28
    /**
29
     * Contained elements.
30
     *
31
     * @var array
32
     */
33
    protected $data = [];
34
35
    /**
36
     * Gets the contained elements.
37
     *
38
     * @return array
39
     */
40
    public function get(): array
41
    {
42
        return $this->data;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getIterator(): Traversable
49
    {
50
        return new ArrayIterator($this->data);
51
    }
52
53
    /**
54
     * Remove all contained elements.
55
     */
56
    public function clear()
57
    {
58
        $this->data = [];
59
    }
60
61
    /**
62
     * Checks if no elements are contained.
63
     *
64
     * @return bool
65
     */
66
    public function isEmpty(): bool
67
    {
68
        return empty($this->data);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function count(): int
75
    {
76
        return count($this->data);
77
    }
78
}
79