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

nette / php-generator / 22836119803

09 Mar 2026 02:40AM UTC coverage: 94.264% (+0.2%) from 94.029%
22836119803

push

github

dg
added CLAUDE.md

1890 of 2005 relevant lines covered (94.26%)

0.94 hits per line

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

56.67
/src/PhpGenerator/InterfaceType.php
1
<?php declare(strict_types=1);
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\PhpGenerator;
9

10
use Nette;
11

12

13
/**
14
 * Definition of an interface with properties, methods and constants.
15
 */
16
final class InterfaceType extends ClassLike
17
{
18
        use Traits\ConstantsAware;
19
        use Traits\MethodsAware;
20
        use Traits\PropertiesAware;
21

22
        /** @var list<string> */
23
        private array $extends = [];
24

25

26
        /** @param string|list<string>  $names */
27
        public function setExtends(string|array $names): static
1✔
28
        {
29
                $names = (array) $names;
1✔
30
                $this->validateNames($names);
1✔
31
                $this->extends = $names;
1✔
32
                return $this;
1✔
33
        }
34

35

36
        /** @return list<string> */
37
        public function getExtends(): array
38
        {
39
                return $this->extends;
1✔
40
        }
41

42

43
        /**
44
         * Adds a parent interface.
45
         */
46
        public function addExtend(string $name): static
1✔
47
        {
48
                $this->validateNames([$name]);
1✔
49
                $this->extends[] = $name;
1✔
50
                return $this;
1✔
51
        }
52

53

54
        /**
55
         * Adds a member to the interface.
56
         * @throws Nette\InvalidStateException if the member already exists and $overwrite is false
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
        {
89
                parent::__clone();
×
90
                $this->consts = array_map(fn(Constant $c) => clone $c, $this->consts);
×
91
                $this->methods = array_map(fn(Method $m) => clone $m, $this->methods);
×
92
                $this->properties = array_map(fn(Property $p) => clone $p, $this->properties);
×
93
        }
94
}
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