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

nette / component-model / 7159764400

10 Dec 2023 07:07PM UTC coverage: 84.404%. Remained the same
7159764400

push

github

dg
used generics in phpDoc [WIP]

184 of 218 relevant lines covered (84.4%)

0.84 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

14

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

32

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

45

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

56

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