Completed
Pull Request — master (#5)
by Carlos C
13:10
created

AbstractDeque   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 73
ccs 31
cts 31
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 5 1
A offer() 0 4 1
A getLast() 0 7 2
A element() 0 4 1
A peekLast() 0 7 2
A peek() 0 4 1
A removeLast() 0 7 2
A remove() 0 4 1
A poll() 0 4 1
A pollLast() 0 7 2
A containerInternalName() 0 4 1
1
<?php namespace GenericCollections\Abstracts;
2
3
use GenericCollections\Interfaces\DequeInterface;
4
use GenericCollections\Internal\DataDoubleLinkedList;
5
use GenericCollections\Traits\CollectionMethods;
6
use GenericCollections\Traits\DequeCommonMethods;
7
8
abstract class AbstractDeque extends DataDoubleLinkedList implements DequeInterface
9
{
10
    use CollectionMethods;
11
    use DequeCommonMethods;
12
13 129
    public function add($element)
14
    {
15 129
        $this->addLast($element);
16 123
        return true;
17
    }
18
19 18
    public function offer($element)
20
    {
21 18
        return $this->offerLast($element);
22
    }
23
24 6
    public function getLast()
25
    {
26 6
        if ($this->isEmpty()) {
27 3
            throw new \LogicException('Can not get an element from an empty ' . $this->containerInternalName());
28
        }
29 3
        return $this->storage->top();
30
    }
31
32 6
    public function element()
33
    {
34 6
        return $this->getFirst();
35
    }
36
37 3
    public function peekLast()
38
    {
39 3
        if ($this->isEmpty()) {
40 3
            return null;
41
        }
42 3
        return $this->storage->top();
43
    }
44
45 3
    public function peek()
46
    {
47 3
        return $this->peekFirst();
48
    }
49
50 6
    public function removeLast()
51
    {
52 6
        if ($this->isEmpty()) {
53 3
            throw new \LogicException('Can not remove an element from an empty ' . $this->containerInternalName());
54
        }
55 3
        return $this->storage->pop();
56
    }
57
58 6
    public function remove()
59
    {
60 6
        return $this->removeFirst();
61
    }
62
63 3
    public function poll()
64
    {
65 3
        return $this->pollFirst();
66
    }
67
68 3
    public function pollLast()
69
    {
70 3
        if ($this->isEmpty()) {
71 3
            return null;
72
        }
73 3
        return $this->storage->pop();
74
    }
75
76 72
    protected function containerInternalName()
77
    {
78 72
        return 'deque';
79
    }
80
}
81