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


PHP Stmt::getMethods方法代码示例

本文整理汇总了PHP中PhpParser\Node\Stmt::getMethods方法的典型用法代码示例。如果您正苦于以下问题:PHP Stmt::getMethods方法的具体用法?PHP Stmt::getMethods怎么用?PHP Stmt::getMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhpParser\Node\Stmt的用法示例。


在下文中一共展示了Stmt::getMethods方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: analyze

 public function analyze(Stmt $contextBefore, Stmt $contextAfter)
 {
     $report = new Report();
     $methodsBefore = $contextBefore->getMethods();
     $methodsAfter = $contextAfter->getMethods();
     $methodsBeforeKeyed = [];
     foreach ($methodsBefore as $method) {
         $methodsBeforeKeyed[$method->name] = $method;
     }
     $methodsAfterKeyed = [];
     foreach ($methodsAfter as $method) {
         $methodsAfterKeyed[$method->name] = $method;
     }
     $methodNamesBefore = array_keys($methodsBeforeKeyed);
     $methodNamesAfter = array_keys($methodsAfterKeyed);
     $methodsAdded = array_diff($methodNamesAfter, $methodNamesBefore);
     $methodsRemoved = array_diff($methodNamesBefore, $methodNamesAfter);
     $methodsToVerify = array_intersect($methodNamesBefore, $methodNamesAfter);
     // Here we only care about public methods as they are the only part of the API we care about
     // Removed methods can either be implemented in parent classes or not exist anymore
     foreach ($methodsRemoved as $method) {
         $methodBefore = $methodsBeforeKeyed[$method];
         $data = new ClassMethodRemoved($this->context, $this->fileBefore, $contextBefore, $methodBefore);
         $report->add($this->context, $data);
     }
     foreach ($methodsToVerify as $method) {
         /** @var \PhpParser\Node\Stmt\ClassMethod $methodBefore */
         $methodBefore = $methodsBeforeKeyed[$method];
         /** @var \PhpParser\Node\Stmt\ClassMethod $methodAfter */
         $methodAfter = $methodsAfterKeyed[$method];
         // Leave non-strict comparison here
         if ($methodBefore != $methodAfter) {
             $paramsBefore = $methodBefore->params;
             $paramsAfter = $methodAfter->params;
             // Signature
             $signatureChanged = false;
             if (!Signature::isSameTypehints($paramsBefore, $paramsAfter)) {
                 $data = new ClassMethodParameterChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
                 $report->add($this->context, $data);
                 $signatureChanged = true;
             }
             if (!$signatureChanged && !Signature::isSameVariables($paramsBefore, $paramsAfter)) {
                 $data = new ClassMethodParameterNameChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
                 $report->add($this->context, $data);
             }
             // Different length (considering params with defaults)
             // Difference in source code
             if ($methodBefore->stmts != $methodAfter->stmts) {
                 $data = new ClassMethodImplementationChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
                 $report->add($this->context, $data);
             }
         }
     }
     // Added methods implies MINOR BUMP
     foreach ($methodsAdded as $method) {
         $methodAfter = $methodsAfterKeyed[$method];
         $data = new ClassMethodAdded($this->context, $this->fileAfter, $contextAfter, $methodAfter);
         $report->add($this->context, $data);
     }
     return $report;
 }
开发者ID:nochso,项目名称:php-semver-checker,代码行数:61,代码来源:ClassMethodAnalyzer.php

示例2: analyze

 public function analyze(Stmt $contextBefore, Stmt $contextAfter)
 {
     $report = new Report();
     $methodsBefore = $contextBefore->getMethods();
     $methodsAfter = $contextAfter->getMethods();
     $methodsBeforeKeyed = [];
     foreach ($methodsBefore as $method) {
         $methodsBeforeKeyed[$method->name] = $method;
     }
     $methodsAfterKeyed = [];
     foreach ($methodsAfter as $method) {
         $methodsAfterKeyed[$method->name] = $method;
     }
     $methodNamesBefore = array_keys($methodsBeforeKeyed);
     $methodNamesAfter = array_keys($methodsAfterKeyed);
     $methodsAdded = array_diff($methodNamesAfter, $methodNamesBefore);
     $methodsRemoved = array_diff($methodNamesBefore, $methodNamesAfter);
     $methodsToVerify = array_intersect($methodNamesBefore, $methodNamesAfter);
     // Here we only care about public methods as they are the only part of the API we care about
     // Removed methods can either be implemented in parent classes or not exist anymore
     foreach ($methodsRemoved as $method) {
         $methodBefore = $methodsBeforeKeyed[$method];
         $data = new ClassMethodRemoved($this->context, $this->fileBefore, $contextBefore, $methodBefore);
         $report->add($this->context, $data);
     }
     foreach ($methodsToVerify as $method) {
         /** @var \PhpParser\Node\Stmt\ClassMethod $methodBefore */
         $methodBefore = $methodsBeforeKeyed[$method];
         /** @var \PhpParser\Node\Stmt\ClassMethod $methodAfter */
         $methodAfter = $methodsAfterKeyed[$method];
         // Leave non-strict comparison here
         if ($methodBefore != $methodAfter) {
             $paramsBefore = $methodBefore->params;
             $paramsAfter = $methodAfter->params;
             $signatureResult = Signature::analyze($paramsBefore, $paramsAfter);
             $changes = ['parameter_added' => ClassMethodParameterAdded::class, 'parameter_removed' => ClassMethodParameterRemoved::class, 'parameter_renamed' => ClassMethodParameterNameChanged::class, 'parameter_typing_added' => ClassMethodParameterTypingAdded::class, 'parameter_typing_removed' => ClassMethodParameterTypingRemoved::class, 'parameter_default_added' => ClassMethodParameterDefaultAdded::class, 'parameter_default_removed' => ClassMethodParameterDefaultRemoved::class, 'parameter_default_value_changed' => ClassMethodParameterDefaultValueChanged::class];
             foreach ($changes as $changeType => $class) {
                 if (!$signatureResult[$changeType]) {
                     continue;
                 }
                 if (is_a($class, ClassMethodOperationUnary::class, true)) {
                     $data = new $class($this->context, $this->fileAfter, $contextAfter, $methodAfter);
                 } else {
                     $data = new $class($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
                 }
                 $report->add($this->context, $data);
             }
             // Difference in source code
             // Cast to array because interfaces do not have stmts (= null)
             if (!Implementation::isSame((array) $methodBefore->stmts, (array) $methodAfter->stmts)) {
                 $data = new ClassMethodImplementationChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
                 $report->add($this->context, $data);
             }
         }
     }
     // Added methods implies MINOR BUMP
     foreach ($methodsAdded as $method) {
         $methodAfter = $methodsAfterKeyed[$method];
         $data = new ClassMethodAdded($this->context, $this->fileAfter, $contextAfter, $methodAfter);
         $report->add($this->context, $data);
     }
     return $report;
 }
开发者ID:tomzx,项目名称:php-semver-checker,代码行数:63,代码来源:ClassMethodAnalyzer.php


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