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

nette / utils / 5707056869

pending completion
5707056869

push

github

dg
support for PHP 8.3

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

1580 of 1753 relevant lines covered (90.13%)

0.9 hits per line

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

94.12
/src/Utils/ArrayHash.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Utils;
11

12
use Nette;
13

14

15
/**
16
 * Provides objects to work as array.
17
 * @template T
18
 * @implements \RecursiveArrayIterator<array-key, T>
19
 * @implements \ArrayAccess<array-key, T>
20
 */
21
class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \IteratorAggregate
22
{
23
        /**
24
         * Transforms array to ArrayHash.
25
         * @param  array<T>  $array
26
         * @return static
27
         */
28
        public static function from(array $array, bool $recursive = true)
1✔
29
        {
30
                $obj = new static;
1✔
31
                foreach ($array as $key => $value) {
1✔
32
                        $obj->$key = $recursive && is_array($value)
1✔
33
                                ? static::from($value, true)
1✔
34
                                : $value;
1✔
35
                }
36

37
                return $obj;
1✔
38
        }
39

40

41
        /**
42
         * Returns an iterator over all items.
43
         * @return \RecursiveArrayIterator<array-key, T>
44
         */
45
        public function getIterator(): \RecursiveArrayIterator
46
        {
47
                return new \RecursiveArrayIterator((array) $this);
1✔
48
        }
49

50

51
        /**
52
         * Returns items count.
53
         */
54
        public function count(): int
55
        {
56
                return count((array) $this);
1✔
57
        }
58

59

60
        /**
61
         * Replaces or appends a item.
62
         * @param  array-key  $key
63
         * @param  T  $value
64
         */
65
        public function offsetSet($key, $value): void
66
        {
67
                if (!is_scalar($key)) { // prevents null
1✔
68
                        throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', gettype($key)));
×
69
                }
70

71
                $this->$key = $value;
1✔
72
        }
1✔
73

74

75
        /**
76
         * Returns a item.
77
         * @param  array-key  $key
78
         * @return T
79
         */
80
        #[\ReturnTypeWillChange]
81
        public function offsetGet($key)
82
        {
83
                return $this->$key;
1✔
84
        }
85

86

87
        /**
88
         * Determines whether a item exists.
89
         * @param  array-key  $key
90
         */
91
        public function offsetExists($key): bool
92
        {
93
                return isset($this->$key);
1✔
94
        }
95

96

97
        /**
98
         * Removes the element from this list.
99
         * @param  array-key  $key
100
         */
101
        public function offsetUnset($key): void
102
        {
103
                unset($this->$key);
1✔
104
        }
1✔
105
}
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

© 2026 Coveralls, Inc