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

elephox-dev / framework / 4855566680

pending completion
4855566680

push

github

Ricardo Boss
Moved namespace iteration to its own iterator

1 of 1 new or added line in 1 file covered. (100.0%)

3635 of 5261 relevant lines covered (69.09%)

9.0 hits per line

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

68.42
/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
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
                return current($this->items);
×
66
        }
67

68
        public function next(): mixed
69
        {
70
                return next($this->items);
×
71
        }
72

73
        public function prev(): mixed
74
        {
75
                return prev($this->items);
×
76
        }
77

78
        public function key(): ?int
79
        {
80
                return key($this->items);
×
81
        }
82

83
        public function reset(): mixed
84
        {
85
                return reset($this->items);
×
86
        }
87
}
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