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

nette / utils / 39638515326

21 Oct 2026 04:50PM UTC coverage: 92.495% (-0.06%) from 92.551%
39638515326

push

github

dg
added support for PHP 8.6

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

114 existing lines in 17 files now uncovered.

1861 of 2012 relevant lines covered (92.5%)

0.92 hits per line

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

95.0
/src/Utils/ArrayHash.php
1
<?php declare(strict_types=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
 * Provides objects to work as array.
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
         * Returns an iterator over all items.
41
         * @return \Iterator<array-key, T>
42
         */
43
        public function &getIterator(): \Iterator
1 ✔
44
        {
45
                foreach ((array) $this as $key => $foo) {
1 ✔
46
                        yield $key => $this->$key;
1 ✔
47
                }
48
        }
1 ✔
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 an 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 ✔
UNCOV
68
                        throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', get_debug_type($key)));
×
69
                }
70

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

74

75
        /**
76
         * Returns an 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 an 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 TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc