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

nette / php-generator / 21808450793

09 Feb 2026 12:39AM UTC coverage: 93.947% (+0.1%) from 93.811%
21808450793

push

github

dg
added CLAUDE.md

1816 of 1933 relevant lines covered (93.95%)

0.94 hits per line

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

55.17
/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
 * Definition of an interface with properties, methods and constants.
17
 */
18
final class InterfaceType extends ClassLike
19
{
20
        use Traits\ConstantsAware;
21
        use Traits\MethodsAware;
22
        use Traits\PropertiesAware;
23

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

27

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

37

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

44

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

52

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

71

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

84

85
        public function __clone(): void
86
        {
87
                parent::__clone();
×
88
                $this->consts = array_map(fn(Constant $c) => clone $c, $this->consts);
×
89
                $this->methods = array_map(fn(Method $m) => clone $m, $this->methods);
×
90
                $this->properties = array_map(fn(Property $p) => clone $p, $this->properties);
×
91
        }
92
}
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