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

nette / php-generator / 11958852939

21 Nov 2024 05:51PM UTC coverage: 93.129% (-0.3%) from 93.464%
11958852939

push

github

dg
Interfaces can have properties hooks

14 of 16 new or added lines in 2 files covered. (87.5%)

4 existing lines in 1 file now uncovered.

1613 of 1732 relevant lines covered (93.13%)

0.93 hits per line

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

41.67
/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)],
×
NEW
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
        public function __clone(): void
75
        {
76
                parent::__clone();
×
77
                $clone = fn($item) => clone $item;
×
78
                $this->consts = array_map($clone, $this->consts);
×
79
                $this->methods = array_map($clone, $this->methods);
×
NEW
80
                $this->properties = array_map($clone, $this->properties);
×
81
        }
82
}
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