Skip to content

Commit 3328cb6

Browse files
committed
ClassType: added hasProperty() & hasMethod()
1 parent acff8b1 commit 3328cb6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ public function removeProperty(string $name): self
404404
}
405405

406406

407+
public function hasProperty(string $name): bool
408+
{
409+
return isset($this->properties[$name]);
410+
}
411+
412+
407413
/**
408414
* @param Method[] $methods
409415
* @return static
@@ -461,6 +467,12 @@ public function removeMethod(string $name): self
461467
}
462468

463469

470+
public function hasMethod(string $name): bool
471+
{
472+
return isset($this->methods[$name]);
473+
}
474+
475+
464476
/**
465477
* @throws Nette\InvalidStateException
466478
*/

tests/PhpGenerator/ClassType.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ $p = $class->addProperty('sections', ['first' => true])
5757
->setStatic(true);
5858

5959
Assert::same($p, $class->getProperty('sections'));
60+
Assert::true($class->hasProperty('sections'));
61+
Assert::false($class->hasProperty('unknown'));
6062
Assert::true($p->isStatic());
6163
Assert::null($p->getVisibility());
6264

@@ -67,6 +69,8 @@ $m = $class->addMethod('getHandle')
6769
->setBody('return $this->?;', ['handle']);
6870

6971
Assert::same($m, $class->getMethod('getHandle'));
72+
Assert::true($class->hasMethod('getHandle'));
73+
Assert::false($class->hasMethod('unknown'));
7074
Assert::true($m->isFinal());
7175
Assert::false($m->isStatic());
7276
Assert::false($m->isAbstract());

0 commit comments

Comments
 (0)