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

nette / utils / 22290136219

23 Feb 2026 01:47AM UTC coverage: 93.125% (-0.003%) from 93.128%
22290136219

push

github

dg
added CLAUDE.md

2086 of 2240 relevant lines covered (93.13%)

0.93 hits per line

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

95.24
/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
1✔
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  $key
59
         * @param  T  $value
60
         */
61
        public function offsetSet($key, $value): void
62
        {
63
                if (!is_scalar($key)) { // prevents null
1✔
64
                        throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', get_debug_type($key)));
×
65
                }
66

67
                $this->$key = $value;
1✔
68
        }
1✔
69

70

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

81

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

91

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