Skip to content

Commit d34e60d

Browse files
sanderdlmdg
authored andcommitted
ConstantsAware: added hasConstant() (#133)
1 parent bdb3fc6 commit d34e60d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/PhpGenerator/Traits/ConstantsAware.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ public function removeConstant(string $name): static
6262
unset($this->consts[$name]);
6363
return $this;
6464
}
65+
66+
67+
public function hasConstant(string $name): bool
68+
{
69+
return isset($this->consts[$name]);
70+
}
6571
}

tests/PhpGenerator/ClassType.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ $class->addConstant('ROLE', 'admin');
4141
$class->addConstant('ACTIVE', false)
4242
->setFinal()
4343
->setType('bool');
44+
Assert::true($class->hasConstant('ROLE'));
45+
Assert::false($class->hasConstant('xxx'));
4446

4547
Assert::false($class->isFinal());
4648
Assert::true($class->isAbstract());

0 commit comments

Comments
 (0)