|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of phpDocumentor. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + * |
| 11 | + * @link http://phpdoc.org |
| 12 | + */ |
| 13 | + |
| 14 | +namespace phpDocumentor\Reflection\Php; |
| 15 | + |
| 16 | +use phpDocumentor\Reflection\DocBlock; |
| 17 | +use phpDocumentor\Reflection\Element; |
| 18 | +use phpDocumentor\Reflection\Fqsen; |
| 19 | +use phpDocumentor\Reflection\Location; |
| 20 | +use phpDocumentor\Reflection\Type; |
| 21 | + |
| 22 | +final class Enum_ implements Element |
| 23 | +{ |
| 24 | + /** @var Fqsen Full Qualified Structural Element Name */ |
| 25 | + private $fqsen; |
| 26 | + |
| 27 | + /** @var DocBlock|null */ |
| 28 | + private $docBlock; |
| 29 | + |
| 30 | + /** @var Location|null */ |
| 31 | + private $location; |
| 32 | + |
| 33 | + /** @var EnumCase[] */ |
| 34 | + private $cases = []; |
| 35 | + |
| 36 | + /** @var array<string, Fqsen> */ |
| 37 | + private $implements = []; |
| 38 | + |
| 39 | + /** @var array<string, Method> */ |
| 40 | + private $methods = []; |
| 41 | + |
| 42 | + /** @var array<string, Fqsen> */ |
| 43 | + private $usedTraits = []; |
| 44 | + |
| 45 | + /** @var Type|null */ |
| 46 | + private $backedType; |
| 47 | + |
| 48 | + public function __construct( |
| 49 | + Fqsen $fqsen, |
| 50 | + ?Type $backedType, |
| 51 | + ?DocBlock $docBlock = null, |
| 52 | + ?Location $location = null |
| 53 | + ) { |
| 54 | + if ($location === null) { |
| 55 | + $location = new Location(-1); |
| 56 | + } |
| 57 | + |
| 58 | + $this->fqsen = $fqsen; |
| 59 | + $this->docBlock = $docBlock; |
| 60 | + $this->location = $location; |
| 61 | + $this->backedType = $backedType; |
| 62 | + } |
| 63 | + |
| 64 | + public function getFqsen(): Fqsen |
| 65 | + { |
| 66 | + return $this->fqsen; |
| 67 | + } |
| 68 | + |
| 69 | + public function getName(): string |
| 70 | + { |
| 71 | + return $this->fqsen->getName(); |
| 72 | + } |
| 73 | + |
| 74 | + public function getDocBlock(): ?DocBlock |
| 75 | + { |
| 76 | + return $this->docBlock; |
| 77 | + } |
| 78 | + |
| 79 | + public function getLocation(): ?Location |
| 80 | + { |
| 81 | + return $this->location; |
| 82 | + } |
| 83 | + |
| 84 | + public function addCase(EnumCase $case): void |
| 85 | + { |
| 86 | + $this->cases[(string) $case->getFqsen()] = $case; |
| 87 | + } |
| 88 | + |
| 89 | + /** @return EnumCase[] */ |
| 90 | + public function getCases(): array |
| 91 | + { |
| 92 | + return $this->cases; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Returns the interfaces this enum is implementing. |
| 97 | + * |
| 98 | + * @return Fqsen[] |
| 99 | + */ |
| 100 | + public function getInterfaces(): array |
| 101 | + { |
| 102 | + return $this->implements; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Add an interface Fqsen this enum is implementing. |
| 107 | + */ |
| 108 | + public function addInterface(Fqsen $interface): void |
| 109 | + { |
| 110 | + $this->implements[(string) $interface] = $interface; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Returns the methods of this enum. |
| 115 | + * |
| 116 | + * @return Method[] |
| 117 | + */ |
| 118 | + public function getMethods(): array |
| 119 | + { |
| 120 | + return $this->methods; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Add a method to this enum. |
| 125 | + */ |
| 126 | + public function addMethod(Method $method): void |
| 127 | + { |
| 128 | + $this->methods[(string) $method->getFqsen()] = $method; |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Returns the traits used by this enum. |
| 133 | + * |
| 134 | + * @return Fqsen[] |
| 135 | + */ |
| 136 | + public function getUsedTraits(): array |
| 137 | + { |
| 138 | + return $this->usedTraits; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Add trait fqsen used by this enum. |
| 143 | + */ |
| 144 | + public function addUsedTrait(Fqsen $fqsen): void |
| 145 | + { |
| 146 | + $this->usedTraits[(string) $fqsen] = $fqsen; |
| 147 | + } |
| 148 | + |
| 149 | + public function getBackedType(): ?Type |
| 150 | + { |
| 151 | + return $this->backedType; |
| 152 | + } |
| 153 | +} |
0 commit comments