AbstractDeque::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace GenericCollections\Abstracts;
3
4
use GenericCollections\Exceptions\ContainerIsEmptyException;
5
use GenericCollections\Interfaces\DequeInterface;
6
use GenericCollections\Internal\DataDoubleLinkedList;
7
use GenericCollections\Traits\CollectionMethods;
8
use GenericCollections\Traits\DequeCommonMethods;
9
10
abstract class AbstractDeque extends DataDoubleLinkedList implements DequeInterface
11
{
12
    use CollectionMethods;
13
    use DequeCommonMethods;
14
15 43
    public function add($element)
16
    {
17 43
        $this->addLast($element);
18 41
        return true;
19
    }
20
21 6
    public function offer($element)
22
    {
23 6
        return $this->offerLast($element);
24
    }
25
26 2
    public function getLast()
27
    {
28 2
        if ($this->isEmpty()) {
29 1
            throw new ContainerIsEmptyException($this->containerInternalName(), 'get');
30
        }
31 1
        return $this->storage->top();
32
    }
33
34 2
    public function element()
35
    {
36 2
        return $this->getFirst();
37
    }
38
39 1
    public function peekLast()
40
    {
41 1
        if ($this->isEmpty()) {
42 1
            return null;
43
        }
44 1
        return $this->storage->top();
45
    }
46
47 1
    public function peek()
48
    {
49 1
        return $this->peekFirst();
50
    }
51
52 2
    public function removeLast()
53
    {
54 2
        if ($this->isEmpty()) {
55 1
            throw new ContainerIsEmptyException($this->containerInternalName(), 'remove');
56
        }
57 1
        return $this->storage->pop();
58
    }
59
60 2
    public function remove()
61
    {
62 2
        return $this->removeFirst();
63
    }
64
65 1
    public function poll()
66
    {
67 1
        return $this->pollFirst();
68
    }
69
70 1
    public function pollLast()
71
    {
72 1
        if ($this->isEmpty()) {
73 1
            return null;
74
        }
75 1
        return $this->storage->pop();
76
    }
77
78 24
    protected function containerInternalName()
79
    {
80 24
        return 'deque';
81
    }
82
}
83