本文整理汇总了PHP中PhpParser\Node\Stmt类的典型用法代码示例。如果您正苦于以下问题:PHP Stmt类的具体用法?PHP Stmt怎么用?PHP Stmt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* @param Stmt $classStmt
* @param $namespace
* @param $source
* @return Element\ClassModel
*/
public function parse(Stmt $classStmt, $namespace, $source)
{
$attrs = $classStmt->getAttributes();
$class = $this->classFactory->create($classStmt->name);
$class->setNamespace($namespace);
$class->setSource($source, $attrs['startLine'], 0);
// annotation
$this->commentsParser->parse($attrs, $class);
// property
$properties = array_filter($classStmt->stmts, function ($stmt) {
return $this->propertyParser->match($stmt);
});
array_map(function (Stmt $propertiesStmt) use($class) {
$prop = $this->propertyParser->parse($propertiesStmt, $class);
$this->propertyAnnotationParser->parse($propertiesStmt, $prop, $class);
$varAnnotations = $prop->annotations->withName('var');
if (!$varAnnotations->isEmpty()) {
/** @var Element\Annotation $var */
$var = $varAnnotations->first();
$prop->setAccessModifier($var->parameters);
}
}, $properties);
// method
$methods = array_filter($classStmt->stmts, function ($stmt) {
return $this->methodParser->match($stmt);
});
array_map(function ($methodStmt) use($class) {
$this->methodParser->parse($methodStmt, $class);
}, $methods);
return $class;
}
示例2: pass
/**
* @param Stmt $stmt
* @param Context $context
* @return bool
*/
public function pass(Stmt $stmt, Context $context)
{
if ($stmt->getDocComment() === null) {
$context->notice('missing_docblock', 'Missing Docblock', $stmt);
return true;
}
return false;
}
示例3: createFunction
/**
* @inheritdoc
* @param Stmt\ClassMethod $function
*/
public function createFunction(Stmt $function)
{
assert($function instanceof Stmt\ClassMethod, 'Only accepts class methods');
if ($function->isStatic()) {
return $this->traitCreateFunction($function);
} else {
return $this->instanceEnvironment->createFunction($function);
}
}
示例4: getForContext
/**
* @param \PhpParser\Node\Stmt $context
* @return int
*/
public static function getForContext(Stmt $context)
{
if ($context->isPublic()) {
return Class_::MODIFIER_PUBLIC;
} elseif ($context->isProtected()) {
return Class_::MODIFIER_PROTECTED;
} else {
return Class_::MODIFIER_PRIVATE;
}
}
示例5: inspectParams
/**
* @param Stmt\ClassMethod|Stmt\Function_ $stmt
* @param Context $context
* @return bool
*/
private function inspectParams(Stmt $stmt, Context $context)
{
/** @var \PhpParser\Node\Param $param */
foreach ($stmt->getParams() as $param) {
if ($param->name === 'this') {
$context->notice('unexpected_use.this', sprintf('Method/Function %s can not have a parameter named "this".', $stmt->name), $param);
return true;
}
}
return false;
}
示例6: pass
/**
* @param Stmt $func
* @param Context $context
* @return bool
*/
public function pass(Stmt $func, Context $context)
{
$prevIsOptional = false;
foreach ($func->getParams() as $param) {
if ($prevIsOptional && $param->default === null) {
$context->notice('optional-param-before-required', 'Optional parameter before required one is always required.', $func);
return true;
}
$prevIsOptional = $param->default !== null;
}
return false;
}
示例7: pass
/**
* @param Stmt $stmt
* @param Context $context
* @return bool
*/
public function pass(Stmt $stmt, Context $context)
{
// if it is private, protected or public return false
if ($stmt->isPrivate() || $stmt->isProtected() || ($stmt->type & Class_::MODIFIER_PUBLIC) !== 0) {
return false;
}
if ($stmt instanceof Property) {
$context->notice('missing_visibility', 'Class property was defined with the deprecated var keyword. Use a visibility modifier instead.', $stmt);
} elseif ($stmt instanceof ClassMethod) {
$context->notice('missing_visibility', 'Class method was defined without a visibility modifier.', $stmt);
}
return true;
}
示例8: __construct
/**
* Constructs a try catch node.
*
* @param Node[] $stmts Statements
* @param Catch_[] $catches Catches
* @param Node[] $finallyStmts Finally statements (null means no finally clause)
* @param array|null $attributes Additional attributes
*/
public function __construct(array $stmts, array $catches, array $finallyStmts = null, array $attributes = array())
{
if (empty($catches) && null === $finallyStmts) {
throw new Error('Cannot use try without catch or finally');
}
parent::__construct(array('stmts' => $stmts, 'catches' => $catches, 'finallyStmts' => $finallyStmts), $attributes);
}
示例9: pass
/**
* @param Stmt $stmt
* @param Context $context
* @return bool
*/
public function pass(Stmt $stmt, Context $context)
{
if ($stmt instanceof Stmt\ClassMethod && $stmt->isAbstract()) {
// abstract classes are ok
return false;
}
if ($stmt instanceof Stmt\Switch_) {
$counting = $stmt->cases;
} else {
$counting = $stmt->stmts;
}
if (count($counting) === 0) {
$context->notice('missing_body', 'Missing Body', $stmt);
return true;
}
return false;
}
示例10: __construct
/**
* Constructs a try catch node.
*
* @param Node[] $stmts Statements
* @param Catch_[] $catches Catches
* @param null|Finally_ $finally Optionaly finally node
* @param array|null $attributes Additional attributes
*/
public function __construct(array $stmts, array $catches, Finally_ $finally = null, array $attributes = array())
{
parent::__construct($attributes);
$this->stmts = $stmts;
$this->catches = $catches;
$this->finally = $finally;
}
示例11: __construct
/**
* Constructs a group use node.
*
* @param Name $prefix
* Prefix for uses
* @param UseUse[] $uses
* Uses
* @param int $type
* Type of group use
* @param array $attributes
* Additional attributes
*/
public function __construct(Name $prefix, array $uses, $type = Use_::TYPE_NORMAL, array $attributes = array())
{
parent::__construct($attributes);
$this->type = $type;
$this->prefix = $prefix;
$this->uses = $uses;
}
示例12: __construct
/**
* Constructs a catch node.
*
* @param Node\Name $type
* Class of exception
* @param string $var
* Variable for exception
* @param Node[] $stmts
* Statements
* @param array $attributes
* Additional attributes
*/
public function __construct(Node\Name $type, $var, array $stmts = array(), array $attributes = array())
{
parent::__construct($attributes);
$this->type = $type;
$this->var = $var;
$this->stmts = $stmts;
}
示例13: __construct
/**
* Constructs a class property list node.
*
* @param int $flags Modifiers
* @param PropertyProperty[] $props Properties
* @param array $attributes Additional attributes
*/
public function __construct($flags, array $props, array $attributes = array())
{
parent::__construct($attributes);
$this->flags = $flags;
$this->type = $flags;
$this->props = $props;
}
示例14: __construct
/**
* Constructs a catch node.
*
* @param Node\Name[] $types Types of exceptions to catch
* @param string $var Variable for exception
* @param Node[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $types, $var, array $stmts = array(), array $attributes = array())
{
parent::__construct($attributes);
$this->types = $types;
$this->var = $var;
$this->stmts = $stmts;
}
示例15: __construct
/**
* Constructs a for loop node.
*
* @param array $subNodes Array of the following optional subnodes:
* 'init' => array(): Init expressions
* 'cond' => array(): Loop conditions
* 'loop' => array(): Loop expressions
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $subNodes = array(), array $attributes = array())
{
parent::__construct(null, $attributes);
$this->init = isset($subNodes['init']) ? $subNodes['init'] : array();
$this->cond = isset($subNodes['cond']) ? $subNodes['cond'] : array();
$this->loop = isset($subNodes['loop']) ? $subNodes['loop'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
}