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

nette / utils / 20431395313

22 Dec 2025 12:06PM UTC coverage: 93.164% (+71.8%) from 21.324%
20431395313

push

github

dg
Html::addText() accepts int|null for back compatibility [Closes #332][Closes #333]

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

140 existing lines in 15 files now uncovered.

2058 of 2209 relevant lines covered (93.16%)

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
 * Provides objects to work as array.
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
         * Returns an iterator over all items.
43
         * @return \Iterator<array-key, T>
44
         */
45
        public function &getIterator(): \Iterator
1✔
46
        {
47
                foreach ((array) $this as $key => $foo) {
1✔
48
                        yield $key => $this->$key;
1✔
49
                }
50
        }
1✔
51

52

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

61

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

73
                $this->$key = $value;
1✔
74
        }
1✔
75

76

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

88

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

98

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

© 2025 Coveralls, Inc