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

nette / utils / 21636962765

03 Feb 2026 03:39PM UTC coverage: 93.312% (+0.05%) from 93.264%
21636962765

push

github

dg
added CLAUDE.md

2065 of 2213 relevant lines covered (93.31%)

0.93 hits per line

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

95.0
/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
use function count, is_array, is_scalar, sprintf;
14

15

16
/**
17
 * Array-like object with property access.
18
 * @template T
19
 * @implements \IteratorAggregate<array-key, T>
20
 * @implements \ArrayAccess<array-key, T>
21
 */
22
class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \IteratorAggregate
23
{
24
        /**
25
         * Transforms array to ArrayHash.
26
         * @param  array<T>  $array
27
         */
28
        public static function from(array $array, bool $recursive = true): static
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)
1✔
34
                                : $value;
1✔
35
                }
36

37
                return $obj;
1✔
38
        }
39

40

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

51

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

57

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

69
                $this->$key = $value;
1✔
70
        }
1✔
71

72

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

83

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

93

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