Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'version2_ast' of github.com:phpmetrics/PhpMetrics into …
…version2_ast
- Loading branch information
Showing
15 changed files
with
260 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Jean-François Lépine <https://twitter.com/Halleck45> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Hal\Component\Ast; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeTraverser as Mother; | ||
|
||
/** | ||
* Custom Ast Traverser | ||
* | ||
* @author Jean-François Lépine <https://twitter.com/Halleck45> | ||
*/ | ||
class NodeTraverser extends Mother | ||
{ | ||
protected $stopCondition; | ||
|
||
public function __construct($cloneNodes = false, $stopCondition = null) | ||
{ | ||
parent::__construct($cloneNodes); | ||
$this->stopCondition = $stopCondition; | ||
} | ||
|
||
protected function traverseArray(array $nodes) { | ||
$doNodes = array(); | ||
|
||
foreach ($nodes as $i => &$node) { | ||
if (is_array($node)) { | ||
$node = $this->traverseArray($node); | ||
} elseif ($node instanceof Node) { | ||
$traverseChildren = true; | ||
|
||
// custom stop condition | ||
if($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Interface_) { | ||
$traverseChildren = false; | ||
} | ||
|
||
foreach ($this->visitors as $visitor) { | ||
$return = $visitor->enterNode($node); | ||
if (self::DONT_TRAVERSE_CHILDREN === $return) { | ||
$traverseChildren = false; | ||
} else if (null !== $return) { | ||
$node = $return; | ||
} | ||
} | ||
|
||
if ($traverseChildren) { | ||
$node = $this->traverseNode($node); | ||
} | ||
|
||
foreach ($this->visitors as $visitor) { | ||
$return = $visitor->leaveNode($node); | ||
|
||
if (self::REMOVE_NODE === $return) { | ||
$doNodes[] = array($i, array()); | ||
break; | ||
} elseif (is_array($return)) { | ||
$doNodes[] = array($i, $return); | ||
break; | ||
} elseif (null !== $return) { | ||
$node = $return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (!empty($doNodes)) { | ||
while (list($i, $replace) = array_pop($doNodes)) { | ||
array_splice($nodes, $i, 1, $replace); | ||
} | ||
} | ||
|
||
return $nodes; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
namespace Hal\Metric; | ||
|
||
class ClassMetric implements Metric | ||
class ClassMetric implements Metric, \JsonSerializable | ||
{ | ||
use BagTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
namespace Hal\Metric; | ||
|
||
class FileMetric implements Metric | ||
class FileMetric implements Metric, \JsonSerializable | ||
{ | ||
use BagTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
namespace Hal\Metric; | ||
|
||
class FunctionMetric implements Metric | ||
class FunctionMetric implements Metric, \JsonSerializable | ||
{ | ||
use BagTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
namespace Hal\Metric; | ||
|
||
class ProjectMetric implements Metric | ||
class ProjectMetric implements Metric, \JsonSerializable | ||
{ | ||
use BagTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.