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

nette / component-model / 19785644860

29 Nov 2025 03:13PM UTC coverage: 86.256% (+0.3%) from 85.981%
19785644860

push

github

dg
used generics in phpDoc [WIP]

182 of 211 relevant lines covered (86.26%)

0.86 hits per line

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

81.82
/src/ComponentModel/ArrayAccess.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\ComponentModel;
11

12
use Nette;
13
use function is_int;
14

15

16
/**
17
 * Implementation of \ArrayAccess for IContainer.
18
 * @template T of IComponent
19
 */
20
trait ArrayAccess
21
{
22
        /**
23
         * Adds the component to the container.
24
         * @param  string|int  $name
25
         * @param  T  $component
26
         */
27
        public function offsetSet($name, $component): void
28
        {
29
                $name = is_int($name) ? (string) $name : $name;
1✔
30
                $this->addComponent($component, $name);
1✔
31
        }
1✔
32

33

34
        /**
35
         * Returns component specified by name. Throws exception if component doesn't exist.
36
         * @param  string|int  $name
37
         * @return T
38
         * @throws Nette\InvalidArgumentException
39
         */
40
        public function offsetGet($name): IComponent
41
        {
42
                $name = is_int($name) ? (string) $name : $name;
1✔
43
                return $this->getComponent($name);
1✔
44
        }
45

46

47
        /**
48
         * Does component specified by name exists?
49
         * @param  string|int  $name
50
         */
51
        public function offsetExists($name): bool
52
        {
53
                $name = is_int($name) ? (string) $name : $name;
×
54
                return $this->getComponent($name, throw: false) !== null;
×
55
        }
56

57

58
        /**
59
         * Removes component from the container.
60
         * @param  string|int  $name
61
         */
62
        public function offsetUnset($name): void
63
        {
64
                $name = is_int($name) ? (string) $name : $name;
1✔
65
                if ($component = $this->getComponent($name, throw: false)) {
1✔
66
                        $this->removeComponent($component);
1✔
67
                }
68
        }
1✔
69
}
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