• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHP-Alchemist / coreFiles / 15423039583

03 Jun 2025 04:45PM UTC coverage: 92.512%. First build
15423039583

Pull #9

github

druid628
corrects typ on AbstractList
Pull Request #9: [Release] v3.0.0

136 of 167 new or added lines in 16 files covered. (81.44%)

556 of 601 relevant lines covered (92.51%)

4.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/src/Abstract/NaturalArray.php
1
<?php
2

3
namespace PHPAlchemist\Abstract;
4

5
use PHPAlchemist\Trait\Array\OnClearTrait;
6
use PHPAlchemist\Trait\Array\OnInsertTrait;
7
use PHPAlchemist\Trait\Array\OnRemoveTrait;
8
use PHPAlchemist\Trait\Array\OnSetTrait;
9

10
abstract class NaturalArray
11
{
12
    use OnInsertTrait;
13
    use OnRemoveTrait;
14
    use OnClearTrait;
15
    use OnSetTrait;
16

17
    /**
18
     * Whether a offset exists.
19
     *
20
     * @link   https://php.net/manual/en/arrayaccess.offsetexists.php
21
     *
22
     * @param mixed $offset <p>
23
     *                      An offset to check for.
24
     *                      </p>
25
     *
26
     * @return bool true on success or false on failure.
27
     *              </p>
28
     *              <p>
29
     *              The return value will be casted to boolean if non-boolean was returned.
30
     *
31
     * @since  5.0.0
32
     */
33
    public function offsetExists(mixed $offset) : bool
25✔
34
    {
35
        return isset($this->data[$offset]);
25✔
36
    }
37

38
    /**
39
     * Offset to retrieve.
40
     *
41
     * @param mixed $offset The offset to retrieve.
42
     *
43
     * @return mixed Can return all value types.
44
     */
45
    public function offsetGet(mixed $offset) : mixed
21✔
46
    {
47
        if ($this->offsetExists($offset)) {
21✔
48
            return $this->data[$offset];
18✔
49
        }
50

51
        return null;
3✔
52
    }
53

54
    public function count() : int
8✔
55
    {
56
        return count($this->data);
8✔
57
    }
58

59
    public function getData() : array
19✔
60
    {
61
        return $this->data;
19✔
62
    }
63

NEW
64
    public function isEmpty() : bool
×
65
    {
NEW
66
        return empty($this->data);
×
67
    }
68

69
    public function current() : mixed
7✔
70
    {
71
        return ($this->valid()) ? array_values($this->data)[$this->position] : false;
7✔
72
    }
73

74
    public function next() : void
9✔
75
    {
76
        $this->position++;
9✔
77
    }
78

79
    public function key() : mixed
4✔
80
    {
81
        return array_keys($this->data)[$this->position];
4✔
82
    }
83

84
    public function valid() : bool
7✔
85
    {
86
        return isset(array_values($this->data)[$this->position]);
7✔
87
    }
88

89
    public function rewind() : void
7✔
90
    {
91
        $this->position = 0;
7✔
92
    }
93

94
    /**
95
     * Move back to previous element.
96
     *
97
     * @return void Any returned value is ignored.
98
     */
99
    public function prev() : void
2✔
100
    {
101
        $this->position--;
2✔
102
    }
103

104
    public function clear() : void
4✔
105
    {
106
        if (isset($this->onClear) && is_callable($this->onClear)) {
4✔
107
            $onClear = $this->onClear;
2✔
108
            $onClear($this->data);
2✔
109
        }
110

111
        $this->data = [];
4✔
112
        $this->rewind();
4✔
113

114
        if (isset($this->onClearComplete) && is_callable($this->onClearComplete)) {
4✔
115
            $onClearComplete = $this->onClearComplete;
2✔
116
            $onClearComplete($this->data);
2✔
117
        }
118
    }
119

120
    public function first() : mixed
1✔
121
    {
122
        return $this->data[array_key_first($this->data)];
1✔
123
    }
124

125
    public function extract(mixed $key) : mixed
2✔
126
    {
127
        $returnValue = $this->data[$key];
2✔
128
        $this->delete($key);
2✔
129
        return $returnValue;
2✔
130
    }
131

132
    public function delete(mixed $key) : void
7✔
133
    {
134
        if (array_key_exists($key, $this->data)) {
7✔
135
            $this->offsetUnset($key);
7✔
136
        }
137
    }
138

139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc