当前位置: 首页>>代码示例>>PHP>>正文


PHP Node\Stmt类代码示例

本文整理汇总了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;
 }
开发者ID:domaincoder,项目名称:code-metamodel-php,代码行数:37,代码来源:ClassParser.php

示例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;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:13,代码来源:MissingDocblock.php

示例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);
     }
 }
开发者ID:lowjoel,项目名称:phortress,代码行数:13,代码来源:ClassEnvironment.php

示例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;
     }
 }
开发者ID:tomzx,项目名称:php-semver-checker,代码行数:14,代码来源:Visibility.php

示例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;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:16,代码来源:UnexpectedUseOfThis.php

示例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;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:17,代码来源:OptionalParamBeforeRequired.php

示例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;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:18,代码来源:MissingVisibility.php

示例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);
 }
开发者ID:Ingothq,项目名称:multiarmedbandit,代码行数:15,代码来源:TryCatch.php

示例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;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:22,代码来源:MissingBody.php

示例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;
 }
开发者ID:nikic,项目名称:php-parser,代码行数:15,代码来源:TryCatch.php

示例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;
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:19,代码来源:GroupUse.php

示例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;
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:19,代码来源:Catch_.php

示例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;
 }
开发者ID:nikic,项目名称:php-parser,代码行数:14,代码来源:Property.php

示例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;
 }
开发者ID:nikic,项目名称:php-parser,代码行数:15,代码来源:Catch_.php

示例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();
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:18,代码来源:For_.php


注:本文中的PhpParser\Node\Stmt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。