From 7544100d1894516b0ad6993db5a119e71ccc2a51 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Wed, 22 Oct 2014 10:37:22 -0400 Subject: [PATCH] More initial work --- lib/ReckiCT/{ => Graph}/Class_.php | 10 +++++++++- lib/ReckiCT/Parser/Parser.php | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) rename lib/ReckiCT/{ => Graph}/Class_.php (70%) diff --git a/lib/ReckiCT/Class_.php b/lib/ReckiCT/Graph/Class_.php similarity index 70% rename from lib/ReckiCT/Class_.php rename to lib/ReckiCT/Graph/Class_.php index e4e1589..c399a88 100644 --- a/lib/ReckiCT/Class_.php +++ b/lib/ReckiCT/Graph/Class_.php @@ -1,12 +1,16 @@ name = $name; @@ -26,4 +30,8 @@ public function getImplements() { return $this->implements; } + public function addMethod(Method $method) { + $this->methods[] = $method; + } + } \ No newline at end of file diff --git a/lib/ReckiCT/Parser/Parser.php b/lib/ReckiCT/Parser/Parser.php index a194d05..78fe1e2 100644 --- a/lib/ReckiCT/Parser/Parser.php +++ b/lib/ReckiCT/Parser/Parser.php @@ -21,6 +21,7 @@ namespace ReckiCT\Parser; +use ReckiCT\Graph\Class_; use ReckiCT\Graph\Vertex; use ReckiCT\Graph\Variable as JitVariable; use ReckiCT\Graph\Constant as JitConstant; @@ -32,6 +33,7 @@ use PhpParser\Node\Scalar; use PhpParser\Node\Expr\Variable as AstVariable; use PhpParser\Node\Stmt\Class_ as AstClass; +use PhpParser\Node\Stmt\ClassMethod as AstClassMethod; use PhpParser\Node\Stmt\Function_ as AstFunction; use Gliph\Graph\DirectedAdjacencyList; @@ -46,7 +48,26 @@ public function addRule(Rule $rule) public function parseClass(AstClass $ast) { - throw new \BadMethodCallException("Not implemented yet"); + var_dump($ast); + $implements = []; + foreach ($ast->implements as $interface) { + $implements[] = $interface->toString(); + } + $class = new Class_( + $ast->namespacedName->toString(), + $ast->extends ? $ast->extends->toString() : null, + $implements + ); + + foreach ($ast->stmts as $stmt) { + switch (get_class($stmt)) { + case AstClassMethod::class: + break; + default: + throw new \LogicException("Unexpected child type found: " . get_class($stmt)); + } + } + return $class; } public function parseFunction(AstFunction $ast)