public function visitStruct(ClassLike $node) { $struct = $this->getStruct(); $struct->setName($node->name); if (($doc = $node->getDocComment()) !== null) { $struct->setDocblock($doc->getReformattedText()); $docblock = $struct->getDocblock(); $struct->setDescription($docblock->getShortDescription()); $struct->setLongDescription($docblock->getLongDescription()); } }
private function importMethods(ClassLike $class, array $methods) { $stmts = []; foreach ($methods as $methodName => $methodArr) { if (count($methodArr) > 1) { echo "Too many implementations for {$methodName}\n"; } foreach ($methodArr as $traitName => $method) { if (!$class->getMethod($method->name)) { $stmts[] = $method; } } } return $stmts; }
/** * Constructs a class node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'extends' => array(): Name of extended interfaces * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct($attributes); $this->name = $name; $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array(); $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array(); }
/** * Parses interfaces from the concrete class node * * @param ClassLike $classLikeNode Class-like node * * @return array|\ReflectionClass[] List of reflections of interfaces */ public static function collectInterfacesFromClassNode(ClassLike $classLikeNode) { $interfaces = []; $isInterface = $classLikeNode instanceof Interface_; $interfaceField = $isInterface ? 'extends' : 'implements'; $hasInterfaces = in_array($interfaceField, $classLikeNode->getSubNodeNames()); $implementsList = $hasInterfaces ? $classLikeNode->{$interfaceField} : array(); if ($implementsList) { foreach ($implementsList as $implementNode) { if ($implementNode instanceof FullyQualified) { $implementName = $implementNode->toString(); $interface = interface_exists($implementName, false) ? new parent($implementName) : new static($implementName); $interfaces[$implementName] = $interface; } } } return $interfaces; }
/** * Constructs a class node. * * @param string|null $name Name * @param array $subNodes Array of the following optional subnodes: * 'flags' => 0 : Flags * 'extends' => null : Name of extended class * 'implements' => array(): Names of implemented interfaces * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct($attributes); $this->flags = isset($subNodes['flags']) ? $subNodes['flags'] : (isset($subNodes['type']) ? $subNodes['type'] : 0); $this->type = $this->flags; $this->name = $name; $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null; $this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array(); $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array(); }
/** * Constructs a class node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'extends' => array(): Name of extended interfaces * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct(array('name' => $name, 'extends' => isset($subNodes['extends']) ? $subNodes['extends'] : array(), 'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array()), $attributes); if (isset(self::$specialNames[(string) $this->name])) { throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name)); } foreach ($this->extends as $interface) { if (isset(self::$specialNames[(string) $interface])) { throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface)); } } }
/** * Constructs a class node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'extends' => array(): Name of extended interfaces * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct($attributes); $this->name = $name; $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array(); $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array(); if (isset(self::$specialNames[strtolower($this->name)])) { throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name)); } foreach ($this->extends as $interface) { if (isset(self::$specialNames[strtolower($interface)])) { throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), $interface->getAttributes()); } } }
/** * Constructs a class node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'type' => 0 : Type * 'extends' => null : Name of extended class * 'implements' => array(): Names of implemented interfaces * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct(null, $attributes); $this->type = isset($subNodes['type']) ? $subNodes['type'] : 0; $this->name = $name; $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null; $this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array(); $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array(); if (isset(self::$specialNames[(string) $this->name])) { throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name)); } if (isset(self::$specialNames[(string) $this->extends])) { throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends)); } foreach ($this->implements as $interface) { if (isset(self::$specialNames[(string) $interface])) { throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface)); } } }
/** * Constructs a trait node. * * @param string $name * Name * @param Node[] $stmts * Statements * @param array $attributes * Additional attributes */ public function __construct($name, array $stmts = array(), array $attributes = array()) { parent::__construct($attributes); $this->name = $name; $this->stmts = $stmts; }
/** * Is this class a final class. * * @return bool */ public function isFinal() { return $this->node instanceof ClassNode && $this->node->isFinal(); }
/** * Constructs a trait node. * * @param string $name Name * @param Node[] $stmts Statements * @param array $attributes Additional attributes */ public function __construct($name, array $stmts = array(), array $attributes = array()) { parent::__construct(array('name' => $name, 'stmts' => $stmts), $attributes); }
/** * {@inheritDoc} */ public function isFinal() { $isFinal = $this->classLikeNode instanceof Class_ && $this->classLikeNode->isFinal(); return $isFinal; }
/** * Parses methods from the concrete class node * * @param ClassLike $classLikeNode Class-like node * @param ReflectionClass $reflectionClass Reflection of the class * * @return array|ReflectionMethod[] */ public static function collectFromClassNode(ClassLike $classLikeNode, ReflectionClass $reflectionClass) { $methods = []; foreach ($classLikeNode->stmts as $classLevelNode) { if ($classLevelNode instanceof ClassMethod) { $classLevelNode->setAttribute('fileName', $classLikeNode->getAttribute('fileName')); $methodName = $classLevelNode->name; $methods[$methodName] = new ReflectionMethod($reflectionClass->name, $methodName, $classLevelNode, $reflectionClass); } } return $methods; }
private function detectAndHandleReservedNames(Node\Stmt\ClassLike $cls) { $this->handleClassName($cls->name, $cls->getLine()); }