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

nette / php-generator / 12008046975

25 Nov 2024 10:27AM UTC coverage: 91.707% (-1.5%) from 93.222%
12008046975

push

github

dg
Factory & Extractor: added support for property hooks & asymmetric visiblity WIP

39 of 66 new or added lines in 2 files covered. (59.09%)

33 existing lines in 7 files now uncovered.

1725 of 1881 relevant lines covered (91.71%)

0.92 hits per line

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

53.33
/src/PhpGenerator/InterfaceType.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\PhpGenerator;
11

12
use Nette;
13

14

15
/**
16
 * Interface description.
17
 */
18
final class InterfaceType extends ClassLike
19
{
20
        use Traits\ConstantsAware;
21
        use Traits\MethodsAware;
22
        use Traits\PropertiesAware;
23

24
        /** @var string[] */
25
        private array $extends = [];
26

27

28
        /**
29
         * @param  string|string[]  $names
30
         */
31
        public function setExtends(string|array $names): static
1✔
32
        {
33
                $names = (array) $names;
1✔
34
                $this->validateNames($names);
1✔
35
                $this->extends = $names;
1✔
36
                return $this;
1✔
37
        }
38

39

40
        /** @return string[] */
41
        public function getExtends(): array
42
        {
43
                return $this->extends;
1✔
44
        }
45

46

47
        public function addExtend(string $name): static
1✔
48
        {
49
                $this->validateNames([$name]);
1✔
50
                $this->extends[] = $name;
1✔
51
                return $this;
1✔
52
        }
53

54

55
        /**
56
         * Adds a member. If it already exists, throws an exception or overwrites it if $overwrite is true.
57
         */
58
        public function addMember(Method|Constant|Property $member, bool $overwrite = false): static
59
        {
60
                $name = $member->getName();
×
61
                [$type, $n] = match (true) {
×
62
                        $member instanceof Constant => ['consts', $name],
×
63
                        $member instanceof Method => ['methods', strtolower($name)],
×
64
                        $member instanceof Property => ['properties', $name],
×
65
                };
66
                if (!$overwrite && isset($this->$type[$n])) {
×
67
                        throw new Nette\InvalidStateException("Cannot add member '$name', because it already exists.");
×
68
                }
69
                $this->$type[$n] = $member;
×
70
                return $this;
×
71
        }
72

73

74
        /** @throws Nette\InvalidStateException */
75
        public function validate(): void
76
        {
77
                foreach ($this->getProperties() as $property) {
1✔
78
                        if ($property->isInitialized()) {
1✔
79
                                throw new Nette\InvalidStateException("Property {$this->getName()}::\${$property->getName()}: Interface cannot have initialized properties.");
1✔
80
                        } elseif (!$property->getHooks()) {
1✔
81
                                throw new Nette\InvalidStateException("Property {$this->getName()}::\${$property->getName()}: Interface cannot have properties without hooks.");
1✔
82
                        }
83
                }
84
        }
1✔
85

86

87
        public function __clone(): void
88
        {
UNCOV
89
                parent::__clone();
×
UNCOV
90
                $clone = fn($item) => clone $item;
×
UNCOV
91
                $this->consts = array_map($clone, $this->consts);
×
UNCOV
92
                $this->methods = array_map($clone, $this->methods);
×
UNCOV
93
                $this->properties = array_map($clone, $this->properties);
×
94
        }
95
}
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