Completed
Push — master ( e13b70...f3b6bd )
by Stefan
06:13
created

ArrayBuffer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 73
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
1
<?php
2
/*
3
 * Copyright (C) 2017 by TEQneers GmbH & Co. KG
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
/**
25
 * Git Stream Wrapper for PHP
26
 *
27
 * @category   TQ
28
 * @package    TQ_VCS
29
 * @subpackage VCS
30
 * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG
31
 */
32
33
namespace TQ\Vcs\Buffer;
34
35
/**
36
 * Simple class to iterate over an array
37
 *
38
 * @author     Stefan Gehrig <gehrigteqneers.de>
39
 * @category   TQ
40
 * @package    TQ_VCS
41
 * @subpackage VCS
42
 * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG
43
 */
44
class ArrayBuffer implements \Iterator
45
{
46
    /**
47
     * The array
48
     *
49
     * @var array
50
     */
51
    protected $array;
52
53
    /**
54
     * Creates an array buffer from an array
55
     *
56
     * @param   array   $array    The array
57
     */
58 20
    public function __construct(array $array)
59
    {
60 20
        $this->array  = $array;
61 20
        reset($this->array);
62 20
    }
63
64
    /**
65
     * Implements Iterator
66
     *
67
     * @link    http://php.net/manual/en/iterator.current.php
68
     * @return  string
69
     */
70 20
    public function current()
71
    {
72 20
        return current($this->array);
73
    }
74
75
    /**
76
     * Implements Iterator
77
     *
78
     * @link    http://php.net/manual/en/iterator.next.php
79
     */
80 20
    public function next()
81
    {
82 20
        next($this->array);
83 20
    }
84
85
    /**
86
     * Implements Iterator
87
     *
88
     * @link    http://php.net/manual/en/iterator.key.php
89
     * @return  integer|boolean     False on failure
90
     */
91 2
    public function key()
92
    {
93 2
        return key($this->array);
94
    }
95
96
    /**
97
     * Implements Iterator
98
     *
99
     * @link    http://php.net/manual/en/iterator.valid.php
100
     * @return  boolean
101
     */
102 2
    public function valid()
103
    {
104 2
        return (key($this->array) !== null);
105
    }
106
107
    /**
108
     * Implements Iterator
109
     *
110
     * @link    http://php.net/manual/en/iterator.rewind.php
111
     */
112 8
    public function rewind()
113
    {
114 8
        reset($this->array);
115 8
    }
116
}
117