123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php declare(strict_types=1);
- namespace PhpParser\Node\Stmt;
- use PhpParser\Node;
- abstract class ClassLike extends Node\Stmt
- {
-
- public $name;
-
- public $stmts;
-
- public $attrGroups;
-
- public $namespacedName;
-
- public function getTraitUses() : array {
- $traitUses = [];
- foreach ($this->stmts as $stmt) {
- if ($stmt instanceof TraitUse) {
- $traitUses[] = $stmt;
- }
- }
- return $traitUses;
- }
-
- public function getConstants() : array {
- $constants = [];
- foreach ($this->stmts as $stmt) {
- if ($stmt instanceof ClassConst) {
- $constants[] = $stmt;
- }
- }
- return $constants;
- }
-
- public function getProperties() : array {
- $properties = [];
- foreach ($this->stmts as $stmt) {
- if ($stmt instanceof Property) {
- $properties[] = $stmt;
- }
- }
- return $properties;
- }
-
- public function getProperty(string $name) {
- foreach ($this->stmts as $stmt) {
- if ($stmt instanceof Property) {
- foreach ($stmt->props as $prop) {
- if ($prop instanceof PropertyProperty && $name === $prop->name->toString()) {
- return $stmt;
- }
- }
- }
- }
- return null;
- }
-
- public function getMethods() : array {
- $methods = [];
- foreach ($this->stmts as $stmt) {
- if ($stmt instanceof ClassMethod) {
- $methods[] = $stmt;
- }
- }
- return $methods;
- }
-
- public function getMethod(string $name) {
- $lowerName = strtolower($name);
- foreach ($this->stmts as $stmt) {
- if ($stmt instanceof ClassMethod && $lowerName === $stmt->name->toLowerString()) {
- return $stmt;
- }
- }
- return null;
- }
- }
|