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

nette / utils / 38323312841

12 Oct 2026 11:39PM UTC coverage: 93.397% (-0.001%) from 93.398%
38323312841

push

github

dg
added upgrading.md

2136 of 2287 relevant lines covered (93.4%)

0.93 hits per line

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

90.91
/src/Utils/ArrayHash.php
1
<?php declare(strict_types=1);
1 ✔
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
namespace Nette\Utils;
9

10
use Nette;
11
use function count, is_array, is_scalar, sprintf;
12

13

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

35
                return $obj;
1 ✔
36
        }
37

38

39
        /**
40
         * @return \Iterator<array-key, T>
41
         */
42
        public function &getIterator(): \Iterator
1 ✔
43
        {
44
                foreach ((array) $this as $key => $foo) {
1 ✔
45
                        yield $key => $this->$key;
1 ✔
46
                }
47
        }
1 ✔
48

49

50
        public function count(): int
51
        {
52
                return count((array) $this);
1 ✔
53
        }
54

55

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

70
                $this->$offset = $value;
1 ✔
71
        }
1 ✔
72

73

74
        /**
75
         * Returns an item.
76
         * @param  array-key  $offset
77
         * @return T
78
         */
79
        public function offsetGet($offset): mixed
80
        {
81
                return $this->$offset;
1 ✔
82
        }
83

84

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

94

95
        /**
96
         * Removes the element from this list.
97
         * @param  array-key  $offset
98
         */
99
        public function offsetUnset($offset): void
100
        {
101
                unset($this->$offset);
1 ✔
102
        }
1 ✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc