Completed
Push — master ( ff0ae5...10958a )
by Gabriel
02:30
created

OperationsTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 40%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 60
c 1
b 0
f 1
ccs 6
cts 15
cp 0.4
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A size() 0 9 2
A isEmpty() 0 4 1
A isNotEmpty() 0 4 1
A clear() 0 7 1
rewind() 0 1 ?
1
<?php
2
3
namespace Nip\Collections\Traits;
4
5
use Traversable;
6
7
/**
8
 * Class OperationsTrait
9
 * @package Nip\Collections\Traits
10
 */
11
trait OperationsTrait
12
{
13
14
    /**
15
     * Returns the number of parameters.
16
     *
17
     * @return int The number of parameters
18
     */
19 3
    public function count()
20
    {
21 3
        return count($this->items);
0 ignored issues
show
Bug introduced by
The property items does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
    }
23
24
    /**
25
     * Returns number of items in $collection.
26
     *
27
     * @return int
28
     */
29
    public function size()
30
    {
31
        $result = 0;
32
        foreach ($this as $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Nip\Collections\Traits\OperationsTrait> is not traversable.
Loading history...
33
            $result++;
34
        }
35
36
        return $result;
37
    }
38
39
    /**
40
     * @return bool
41
     */
42
    public function isEmpty()
43
    {
44
        return $this->count() < 1;
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    public function isNotEmpty()
51
    {
52
        return !$this->isEmpty();
53
    }
54
55
    /**
56
     * @return $this
57
     */
58 1
    public function clear()
59
    {
60 1
        $this->rewind();
61 1
        $this->items = [];
62
63 1
        return $this;
64
    }
65
66
    /**
67
     * @return void
68
     */
69
    abstract public function rewind();
70
}
71