-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor_collector_cor'
- Loading branch information
Showing
51 changed files
with
2,323 additions
and
1,183 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,86 @@ | ||
<?php | ||
|
||
/* | ||
* Mondrian | ||
*/ | ||
|
||
namespace Trismegiste\Mondrian\Visitor\Edge; | ||
|
||
use PhpParser\Node\Stmt; | ||
|
||
/** | ||
* ClassLevel is ... | ||
*/ | ||
class ClassLevel extends TraitUserHelper | ||
{ | ||
|
||
public function enter(\PhpParser\Node $node) | ||
{ | ||
switch ($node->getType()) { | ||
|
||
case 'Stmt_ClassMethod': | ||
if ($node->isPublic()) { | ||
$this->context->pushState('class-method', $node); | ||
$this->enterPublicMethod($node); | ||
} | ||
break; | ||
|
||
case 'Stmt_TraitUse': | ||
$fqcn = $this->getCurrentFqcn(); | ||
$currentVertex = $this->findVertex('class', $fqcn); | ||
$this->enterTraitUse($node, $currentVertex); | ||
break; | ||
} | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'class'; | ||
} | ||
|
||
protected function enterPublicMethod(Stmt\ClassMethod $node) | ||
{ | ||
// NS | ||
$methodName = $node->name; | ||
$currentFqcn = $this->getCurrentFqcn(); | ||
$declaringFqcn = $this->getReflectionContext()->getDeclaringClass($currentFqcn, $methodName); | ||
// Vertices | ||
$signatureIndex = $declaringFqcn . '::' . $methodName; | ||
$classVertex = $this->findVertex('class', $currentFqcn); | ||
$signatureVertex = $this->findVertex('method', $signatureIndex); | ||
$implVertex = $this->findVertex('impl', $currentFqcn . '::' . $methodName); | ||
|
||
// if current class == declaring class, we add the edge | ||
if ($declaringFqcn == $currentFqcn) { | ||
$this->getGraph()->addEdge($classVertex, $signatureVertex); // C -> M | ||
if (!$node->isAbstract()) { | ||
$this->getGraph()->addEdge($signatureVertex, $implVertex); // M -> S | ||
$this->getGraph()->addEdge($implVertex, $classVertex); // S -> C | ||
} | ||
} else { | ||
if (!$node->isAbstract()) { | ||
$this->getGraph()->addEdge($classVertex, $implVertex); // C -> S | ||
$this->getGraph()->addEdge($implVertex, $classVertex); // S -> C | ||
} | ||
} | ||
|
||
// in any case, we link the implementation to the params | ||
foreach ($node->params as $idx => $param) { | ||
// adding edge from signature to param : | ||
$paramVertex = $this->findVertex('param', $signatureIndex . '/' . $idx); | ||
// it is possible to not find the param because the signature | ||
// is external to the source code : | ||
if (!is_null($paramVertex)) { | ||
if (!$node->isAbstract()) { | ||
$this->getGraph()->addEdge($implVertex, $paramVertex); // S -> P | ||
} | ||
if ($currentFqcn === $declaringFqcn) { | ||
$this->getGraph()->addEdge($signatureVertex, $paramVertex); // M -> P | ||
// now the type of the param : | ||
$this->typeHintParam($param, $paramVertex); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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,25 @@ | ||
<?php | ||
|
||
/* | ||
* Mondrian | ||
*/ | ||
|
||
namespace Trismegiste\Mondrian\Visitor\Edge; | ||
|
||
/** | ||
* ClassMethodLevel is a visitor for method in a class | ||
*/ | ||
class ClassMethodLevel extends MethodLevelHelper | ||
{ | ||
|
||
public function getName() | ||
{ | ||
return 'class-method'; | ||
} | ||
|
||
protected function getParentName() | ||
{ | ||
return 'class'; | ||
} | ||
|
||
} |
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,35 @@ | ||
<?php | ||
|
||
/* | ||
* Mondrian | ||
*/ | ||
|
||
namespace Trismegiste\Mondrian\Visitor\Edge; | ||
|
||
use Trismegiste\Mondrian\Visitor\VisitorGateway; | ||
use Trismegiste\Mondrian\Transform\ReflectionContext; | ||
use Trismegiste\Mondrian\Transform\GraphContext; | ||
use Trismegiste\Mondrian\Graph\Graph; | ||
|
||
/** | ||
* Collector is the main visitor for creating edges between already-created vertices | ||
*/ | ||
class Collector extends VisitorGateway | ||
{ | ||
|
||
public function __construct(ReflectionContext $ref, GraphContext $grf, Graph $g) | ||
{ | ||
$visitor = [ | ||
new \Trismegiste\Mondrian\Visitor\State\PackageLevel(), | ||
new FileLevel(), | ||
new ClassLevel(), | ||
new InterfaceLevel(), | ||
new TraitLevel(), | ||
new ClassMethodLevel(), | ||
new TraitMethodLevel() | ||
]; | ||
|
||
parent::__construct($visitor, $ref, $grf, $g); | ||
} | ||
|
||
} |
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,55 @@ | ||
<?php | ||
|
||
/* | ||
* Mondrian | ||
*/ | ||
|
||
namespace Trismegiste\Mondrian\Visitor\Edge; | ||
|
||
use Trismegiste\Mondrian\Visitor\State\FileLevelTemplate; | ||
use PhpParser\Node\Stmt; | ||
|
||
/** | ||
* FileLevel is ... | ||
*/ | ||
class FileLevel extends FileLevelTemplate | ||
{ | ||
|
||
protected function enterClassNode(Stmt\Class_ $node) | ||
{ | ||
$fqcn = $this->getNamespacedName($node); | ||
$src = $this->findVertex('class', $fqcn); | ||
|
||
// extends | ||
if (!is_null($node->extends)) { | ||
if (null !== $dst = $this->findVertex('class', (string) $this->resolveClassName($node->extends))) { | ||
$this->getGraph()->addEdge($src, $dst); | ||
} | ||
} | ||
// implements | ||
foreach ($node->implements as $interf) { | ||
if (null !== $dst = $this->findVertex('interface', (string) $this->resolveClassName($interf))) { | ||
$this->getGraph()->addEdge($src, $dst); | ||
} | ||
} | ||
} | ||
|
||
protected function enterInterfaceNode(Stmt\Interface_ $node) | ||
{ | ||
$fqcn = $this->getNamespacedName($node); | ||
$src = $this->findVertex('interface', $fqcn); | ||
|
||
// implements | ||
foreach ($node->extends as $interf) { | ||
if (null !== $dst = $this->findVertex('interface', (string) $this->resolveClassName($interf))) { | ||
$this->getGraph()->addEdge($src, $dst); | ||
} | ||
} | ||
} | ||
|
||
protected function enterTraitNode(Stmt\Trait_ $node) | ||
{ | ||
// no edge to create | ||
} | ||
|
||
} |
Oops, something went wrong.