Completed
Pull Request — master (#22)
by
unknown
04:09
created

CollectionIterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 5
c 7
b 2
f 1
lcom 1
cbo 0
dl 0
loc 32
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A rewind() 0 4 1
A key() 0 4 1
A next() 0 4 1
getItem() 0 1 ?
A valid() 0 5 1
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Trait definition:  [NelsonMartell\Collections]  CollectionIterator
7
 * - Class definition:  [NelsonMartell\Collections]  Collection
8
 *
9
 * Copyright © 2015 Nelson Martell (http://nelson6e65.github.io)
10
 *
11
 * Licensed under The MIT License (MIT)
12
 * For full copyright and license information, please see the LICENSE
13
 * Redistributions of files must retain the above copyright notice.
14
 *
15
 * @copyright 2015 Nelson Martell
16
 * @link      http://nelson6e65.github.io/php_nml/
17
 * @since     v0.4.0
18
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
19
 * */
20
21
namespace NelsonMartell\Collections;
22
23
/**
24
 * Implementa los métodos de la interfaz Iterator para una colección de objetos.
25
 *
26
 * @author Nelson Martell <[email protected]>
27
 * @since  v0.4.0
28
 * */
29
trait CollectionIterator
30
{
31
    private $iteratorPosition = 0;
32
33
    public function current()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
34
    {
35
        return $this->getItem($this->iteratorPosition);
36
    }
37
38
    public function rewind()
39
    {
40
        $this->iteratorPosition = 0;
41
    }
42
43
    public function key()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
44
    {
45
        return $this->iteratorPosition;
46
    }
47
48
    public function next()
49
    {
50
        ++$this->iteratorPosition;
51
    }
52
53
    public function valid()
54
    {
55
        $v = (bool) ($this->getItem($this->iteratorPosition) != null);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
56
        return $v;
57
    }
58
59
    protected abstract function getItem($index);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
60
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
61