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

elephox-dev / framework / 4877852653

pending completion
4877852653

push

github

Ricardo Boss
WIP

38 of 38 new or added lines in 6 files covered. (100.0%)

3863 of 5835 relevant lines covered (66.2%)

8.55 hits per line

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

80.0
/modules/Collection/src/IsArrayEnumerable.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Elephox\Collection;
5

6
use LogicException;
7

8
/**
9
 * @template TKey of array-key
10
 * @template TValue
11
 */
12
trait IsArrayEnumerable
13
{
14
        /**
15
         * @var array<TKey, TValue>
16
         */
17
        protected array $items;
18

19
        /**
20
         * @param TValue $value
21
         * @param null|callable(TValue, TValue): bool $comparer
22
         */
23
        public function contains(mixed $value, ?callable $comparer = null): bool
24
        {
25
                if ($comparer === null) {
17✔
26
                        return in_array($value, $this->items, true);
9✔
27
                }
28

29
                foreach ($this->items as $v) {
8✔
30
                        if ($comparer($v, $value)) {
5✔
31
                                return true;
2✔
32
                        }
33
                }
34

35
                return false;
8✔
36
        }
37

38
        /**
39
         * @param TKey $key
40
         * @param null|callable(TKey, TKey): bool $comparer
41
         */
42
        public function containsKey(mixed $key, ?callable $comparer = null): bool
43
        {
44
                if (!is_scalar($key)) {
55✔
45
                        throw new LogicException('Only scalar keys are supported');
×
46
                }
47

48
                if ($comparer === null) {
55✔
49
                        /** @var array-key $key */
50
                        return array_key_exists($key, $this->items);
1✔
51
                }
52

53
                /** @var TKey $k */
54
                foreach ($this->items as $k => $v) {
54✔
55
                        if ($comparer($key, $k)) {
35✔
56
                                return true;
30✔
57
                        }
58
                }
59

60
                return false;
54✔
61
        }
62

63
        public function current(): mixed
64
        {
65
                /** @var TValue|false */
66
                return current($this->items);
2✔
67
        }
68

69
        public function next(): mixed
70
        {
71
                /** @var TValue|false */
72
                return next($this->items);
2✔
73
        }
74

75
        public function prev(): mixed
76
        {
77
                /** @var TValue|false */
78
                return prev($this->items);
×
79
        }
80

81
        public function key(): int|string|null
82
        {
83
                /** @var TKey|null */
84
                return key($this->items);
×
85
        }
86

87
        public function reset(): mixed
88
        {
89
                /** @var TValue|false */
90
                return reset($this->items);
×
91
        }
92

93
        public function count(): int
94
        {
95
                return count($this->items);
42✔
96
        }
97
}
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