private function enterClassMethod(ClassMethod $node) { $methodName = $node->name; if ($this->isGetterOrSetter($methodName) !== true && $this->isNeitherConstructorNorDestructor($methodName)) { $this->methods[$methodName] = $node->isPublic(); } }
private function enterClassMethod(ClassMethod $node) { if ($node->isPublic()) { $methodName = $node->name; if ($this->isGetterOrSetter($methodName)) { $correspondingAttribute = strtolower(substr($methodName, 3)); if (!isset($this->publicMethods[$correspondingAttribute])) { $this->publicMethods[$correspondingAttribute] = array(); } $this->publicMethods[$correspondingAttribute][] = $methodName; } } }
static function getMethodAccessLevel(ClassMethod $level) { if ($level->isPublic()) { return "public"; } if ($level->isPrivate()) { return "private"; } if ($level->isProtected()) { return "protected"; } trigger_error("Impossible"); }
private function getMethodNodeSignature(Node\Stmt\ClassMethod $node) { if ($node->isPublic()) { $accessModifier = FunctionSignature::ACCESS_PUBLIC; } elseif ($node->isProtected()) { $accessModifier = FunctionSignature::ACCESS_PROTECTED; } else { $accessModifier = FunctionSignature::ACCESS_PRIVATE; } if ($node->isFinal()) { $polymorphModifier = FunctionSignature::POLYMORPH_FINAL; } elseif ($node->isAbstract()) { $polymorphModifier = FunctionSignature::POLYMORPH_ABSTRACT; } else { $polymorphModifier = null; } return FunctionSignature::method($node->byRef, $accessModifier, $polymorphModifier, $node->isStatic(), $node->name, $this->getParameterExpressions($node->params)); }
protected function extractStmtClassMethod(Stmt\ClassMethod $node) { return ['Kind' => Grapher::KIND_METHOD, 'Name' => $node->name, 'Path' => $node->namespacedName->toString('/'), 'Exported' => $node->isPublic()]; }
/** * @param ClassMethod $node * * @return RefMethod */ private function createMethod(ClassMethod $node) { $ref = new RefMethod(); $ref->class = $this->class; $ref->name = $node->name; if ($node->isPrivate()) { $ref->visibility = Visibility::IS_PRIVATE; } elseif ($node->isProtected()) { $ref->visibility = Visibility::IS_PROTECTED; } elseif ($node->isPublic()) { $ref->visibility = Visibility::IS_PUBLIC; } $ref->isStatic = $node->isStatic(); $ref->isAbstract = $node->isAbstract(); $ref->isFinal = $node->isFinal(); $ref->startLine = $node->getLine(); $ref->docComment = $this->createDocComment($node); $ref->returnType = $this->getTypeName($node->getReturnType()); foreach ($node->getParams() as $param) { $param = $this->createParam($param, $ref->docComment); $ref->params[$param->name] = $param; } return $ref; }
public function isPublic() : bool { return $this->classMethod->isPublic(); }
/** * Ищвлекает тело метода из текущего узла * * @param Node|ClassMethod $stmt Узел * @param Method[] $methods Список методов * * @return void */ private function extractMethod($stmt, array &$methods) { if (!$stmt instanceof ClassMethod) { return; } $skip = $this->isPublicOnly && $stmt->isPublic() === false; if (!$skip) { $methods[] = new Method(new MethodContext($this->context->namespace, $this->context->class), $stmt->name, $this->printer->prettyPrint([$stmt])); } }
/** * @param Node\Stmt\ClassMethod $node */ protected function parseClassMethodNode(Node\Stmt\ClassMethod $node) { $parameters = []; /** @var \PhpParser\Node\Param $param */ foreach ($node->params as $param) { $parameters[] = ['name' => $param->name, 'type' => (string) $param->type, 'isReference' => $param->byRef, 'isVariadic' => $param->variadic, 'isOptional' => $param->default ? true : false]; } $this->structuralElements[$this->currentStructuralElement->namespacedName->toString()]['methods'][] = ['name' => $node->name, 'startLine' => $node->getLine(), 'isPublic' => $node->isPublic(), 'isPrivate' => $node->isPrivate(), 'isProtected' => $node->isProtected(), 'isStatic' => $node->isStatic(), 'returnType' => $node->getReturnType(), 'parameters' => $parameters, 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null]; }
public function store_class_method(Node\Stmt\Class_ $class, Node\Stmt\ClassMethod $method) { $parameters = array_map(function ($param) { return array('name' => $param->name, 'default' => !empty($param->default), 'type' => ltrim((string) $param->type, '\\')); }, $method->getParams()); $access = array_keys(array_filter(array('public' => $method->isPublic(), 'protected' => $method->isProtected(), 'private' => $method->isPrivate())))[0]; $return_types = array(); $description = ''; if ($comments = $method->getAttribute('comments')) { $phpdoc = new DocBlock($comments[0]->getText()); $description = $phpdoc->getShortDescription(); if ($return = $phpdoc->getTagsByName('return')) { $return_types = array_map('ltrim', explode('|', $return[0]->getType()), array('\\')); } // short circuit @ignore functions if ($phpdoc->hasTag('ignore')) { return; } } $this->store_model('methods', array('method' => $method->name, 'namespace' => !empty($method->namespacedName) ? implode('\\', array_slice($method->namespacedName->parts, 0, -1)) : '', 'file' => $this->_current_file, 'line' => $method->getLine(), 'description' => $description, 'return_types' => json_encode($return_types), 'parameters' => json_encode($parameters), 'access' => $access, 'is_static' => $method->isStatic(), 'class' => $class->name)); }