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

PHP-Alchemist / coreFiles / 15853257391

24 Jun 2025 02:27PM UTC coverage: 92.157%. First build
15853257391

Pull #9

github

druid628
Removes Json in favor of it moving to php-alchemist/json
Pull Request #9: [Release] v3.0.0

113 of 143 new or added lines in 14 files covered. (79.02%)

517 of 561 relevant lines covered (92.16%)

5.06 hits per line

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

96.0
/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 offsetUnset(mixed $offset) : void
11✔
55
    {
56
        if (isset($this->onRemove) && is_callable($this->onRemove)) {
11✔
57
            $onRemove = $this->onRemove;
2✔
58
            $onRemove($offset, $this->data[$offset]);
2✔
59
        }
60

61
        unset($this->data[$offset]);
11✔
62

63
        if (isset($this->onRemoveComplete) && is_callable($this->onRemoveComplete)) {
11✔
64
            $onRemoveComplete = $this->onRemoveComplete;
3✔
65
            $onRemoveComplete($this->data);
3✔
66
        }
67
    }
68

69
    public function count() : int
8✔
70
    {
71
        return count($this->data);
8✔
72
    }
73

74
    public function getData() : array
19✔
75
    {
76
        return $this->data;
19✔
77
    }
78

NEW
79
    public function isEmpty() : bool
×
80
    {
NEW
81
        return empty($this->data);
×
82
    }
83

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

89
    public function next() : void
9✔
90
    {
91
        $this->position++;
9✔
92
    }
93

94
    public function key() : mixed
4✔
95
    {
96
        return array_keys($this->data)[$this->position];
4✔
97
    }
98

99
    public function valid() : bool
7✔
100
    {
101
        return isset(array_values($this->data)[$this->position]);
7✔
102
    }
103

104
    public function rewind() : void
7✔
105
    {
106
        $this->position = 0;
7✔
107
    }
108

109
    /**
110
     * Move back to previous element.
111
     *
112
     * @return void Any returned value is ignored.
113
     */
114
    public function prev() : void
2✔
115
    {
116
        $this->position--;
2✔
117
    }
118

119
    public function clear() : void
4✔
120
    {
121
        if (isset($this->onClear) && is_callable($this->onClear)) {
4✔
122
            $onClear = $this->onClear;
2✔
123
            $onClear($this->data);
2✔
124
        }
125

126
        $this->data = [];
4✔
127
        $this->rewind();
4✔
128

129
        if (isset($this->onClearComplete) && is_callable($this->onClearComplete)) {
4✔
130
            $onClearComplete = $this->onClearComplete;
2✔
131
            $onClearComplete($this->data);
2✔
132
        }
133
    }
134

135
    public function first() : mixed
1✔
136
    {
137
        return $this->data[array_key_first($this->data)];
1✔
138
    }
139

140
    public function extract(mixed $key) : mixed
2✔
141
    {
142
        $returnValue = $this->data[$key];
2✔
143
        $this->delete($key);
2✔
144

145
        return $returnValue;
2✔
146
    }
147

148
    public function delete(mixed $key) : void
7✔
149
    {
150
        if (array_key_exists($key, $this->data)) {
7✔
151
            $this->offsetUnset($key);
7✔
152
        }
153
    }
154
}
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