Skip to content

Commit 1cc6b9c

Browse files
committed
added interfaces' inheritance
Added interfaces' inheritance and looking for methods in collection. Separated scope processing from index processing Added SaveCommand to dump current project to .padawan dir
1 parent ed6e5b2 commit 1cc6b9c

File tree

8 files changed

+90
-27
lines changed

8 files changed

+90
-27
lines changed

specs/completer/resolver/ContextResolver.spec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
expect($context->isObject())->to->be->false;
8888
});
8989
it('hasn\'t type object after object operator with TString and space', function(){
90+
/** @var Context $context */
9091
$context = $this->resolver->getContext('$var->param ');
9192
expect($context->isObject())->to->be->false;
9293
});

src/Command/SaveCommand.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Command;
4+
5+
class SaveCommand extends AbstractCommand {
6+
public function run(array $arguments){
7+
$project = $arguments["project"];
8+
/** @var \IO\Writer $writer */
9+
$writer = $this->get('IO\Writer');
10+
$writer->write($project);
11+
return [
12+
'status' => 'ok'
13+
];
14+
}
15+
}

src/Complete/CompleteEngine.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Complete\Resolver\ScopeResolver;
1515
use Parser\Processor\IndexProcessor;
1616
use Parser\Processor\ScopeProcessor;
17+
use Parser\Processor\ProcessorInterface;
1718
use Psr\Log\LoggerInterface;
1819

1920
class CompleteEngine {
@@ -102,7 +103,6 @@ protected function prepareContent($content, $line, $column){
102103
}
103104

104105
/**
105-
*
106106
* @return Scope
107107
*/
108108
protected function processFileContent(Project $project, $lines, $line, $file){
@@ -127,18 +127,18 @@ protected function processFileContent(Project $project, $lines, $line, $file){
127127
}
128128
if(empty($scopeNodes)) {
129129
$this->indexProcessor->clearResultNodes();
130-
$this->scopeProcessor->clearResultNodes();
131-
$this->scopeProcessor->setIndex($project->getIndex());
132-
$this->scopeProcessor->setLine($line);
133130
$parser = $this->parser;
134131
$parser->addProcessor($this->indexProcessor);
135-
$parser->addProcessor($this->scopeProcessor);
136132
$nodes = $parser->parseContent($fqcn, $file, $content);
137133
$this->generator->processFileNodes(
138134
$project->getIndex(),
139135
$nodes
140136
);
141-
$scopeNodes = $this->scopeProcessor->getResultNodes();
137+
$this->scopeProcessor->setIndex($project->getIndex());
138+
$this->scopeProcessor->setLine($line);
139+
$this->scopeProcessor->clearResultNodes();
140+
$parser->addProcessor($this->scopeProcessor);
141+
$scopeNodes = $parser->parseContent($fqcn, $file, $content);
142142
$contentHash = hash('sha1', $content);
143143
$this->cachePool[$file] = [$contentHash, $nodes, $scopeNodes];
144144
}
@@ -155,7 +155,9 @@ private function isValidCache($file, $content){
155155
private $generator;
156156
private $contextResolver;
157157
private $completerFactory;
158+
/** @property IndexProcessor */
158159
private $indexProcessor;
160+
/** @property ScopeProcessor */
159161
private $scopeProcessor;
160162
private $cachePool;
161163
private $logger;

src/Entity/Collection/MethodsCollection.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class MethodsCollection{
1010
private $methods = [];
11+
/** @property ClassData */
1112
private $class;
1213

1314
public function __construct($class){
@@ -32,16 +33,24 @@ public function get($name, Specification $spec = null){
3233
}
3334
return null;
3435
}
35-
if($this->class instanceof InterfaceData){
36-
return;
36+
$parentSpec =new Specification(
37+
$spec->getParentMode(),
38+
$spec->isStatic(),
39+
$spec->isMagic()
40+
);
41+
if($this->class instanceof ClassData){
42+
$parent = $this->class->getParent();
43+
if($parent instanceof ClassData){
44+
return $parent->methods->get($name, $parentSpec);
45+
}
3746
}
38-
$parent = $this->class->getParent();
39-
if($parent instanceof ClassData){
40-
return $parent->methods->get($name, new Specification(
41-
$spec->getParentMode(),
42-
$spec->isStatic(),
43-
$spec->isMagic()
44-
));
47+
foreach($this->class->getInterfaces() as $interface){
48+
if($interface instanceof InterfaceData){
49+
$method = $interface->methods->get($name, $parentSpec);
50+
if($method instanceof MethodData){
51+
return $method;
52+
}
53+
}
4554
}
4655
}
4756
public function all(Specification $spec = null){
@@ -54,20 +63,27 @@ public function all(Specification $spec = null){
5463
$methods[$method->name] = $method;
5564
}
5665
}
66+
$parentSpec = new Specification(
67+
$spec->getParentMode(),
68+
$spec->isStatic(),
69+
$spec->isMagic()
70+
);
5771
if($this->class instanceof ClassData){
5872
$parent = $this->class->getParent();
5973
if($parent instanceof ClassData){
60-
$parentM = $parent->methods->all(new Specification(
61-
$spec->getParentMode(),
62-
$spec->isStatic(),
63-
$spec->isMagic()
64-
));
74+
$parentM = $parent->methods->all($parentSpec);
6575
$methods = array_merge(
6676
$parentM,
6777
$methods
6878
);
6979
}
7080
}
81+
foreach($this->class->getInterfaces() as $interface){
82+
if($interface instanceof InterfaceData){
83+
$parentM = $interface->methods->all( $parentSpec);
84+
$methods = array_merge($parentM, $methods);
85+
}
86+
}
7187
return $methods;
7288
}
7389
}

src/Entity/Index.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function getInterfaces(){
9696

9797
public function addClass(ClassData $class){
9898
$this->classes[$class->fqcn->toString()] = $class;
99-
if(!empty($class->getParent())){
99+
if($class->getParent() instanceof FQCN){
100100
$this->addExtend($class, $class->getParent());
101101
}
102102
foreach($class->getInterfaces() as $interface){
@@ -114,6 +114,11 @@ public function addInterface(InterfaceData $interface){
114114
foreach($this->findInterfaceChildrenClasses($interface->fqcn) as $child){
115115
$this->addImplement($child, $interface->fqcn);
116116
}
117+
foreach($interface->getInterfaces() as $parent){
118+
if($parent instanceof FQCN){
119+
$this->addImplement($interface, $parent);
120+
}
121+
}
117122
}
118123

119124
public function addFQCN(FQCN $fqcn){
@@ -146,7 +151,7 @@ protected function addExtend(ClassData $class, FQCN $parent){
146151
}
147152
}
148153

149-
protected function addImplement(ClassData $class, FQCN $fqcn){
154+
protected function addImplement($class, FQCN $fqcn){
150155
$this->findInterfaceChildrenClasses($fqcn);
151156
$this->implements[$fqcn->toString()][$class->fqcn->toString()] = $class;
152157
$interface = $this->findInterfaceByFQCN($fqcn);

src/Entity/Node/InterfaceData.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ public function __construct(FQCN $fqcn, $file){
2222
public function addMethod(MethodData $method){
2323
$this->methods->add($method);
2424
}
25+
public function getInterfaces(){
26+
return $this->interfaces;
27+
}
28+
public function addInterface($interface){
29+
$fqcn = $interface;
30+
if($interface instanceof InterfaceData){
31+
$fqcn = $interface->fqcn;
32+
}
33+
$this->interfaces[$fqcn->toString()] = $interface;
34+
}
2535
}

src/Parser/InterfaceParser.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
class InterfaceParser {
1212

13-
public function __construct(MethodParser $methodParser){
13+
public function __construct(
14+
MethodParser $methodParser,
15+
UseParser $useParser
16+
){
1417
$this->methodParser = $methodParser;
18+
$this->useParser = $useParser;
1519
}
1620

1721
/**
@@ -22,19 +26,26 @@ public function __construct(MethodParser $methodParser){
2226
public function parse(Interface_ $node, FQN $fqn, $file)
2327
{
2428
$fqcn = new FQCN($node->name, $fqn);
25-
$interace = new InterfaceData($fqcn, $file);
29+
$interface = new InterfaceData($fqcn, $file);
30+
foreach($node->extends AS $interfaceName){
31+
$interface->addInterface(
32+
$this->useParser->getFQCN($interfaceName)
33+
);
34+
}
2635
foreach($node->stmts AS $child){
2736
if($child instanceof ClassMethod){
28-
$interace->addMethod($this->parseMethod($child));
37+
$interface->addMethod($this->parseMethod($child));
2938
}
3039
}
31-
return $interace;
40+
return $interface;
3241
}
3342

3443
protected function parseMethod(ClassMethod $node){
3544
return $this->methodParser->parse($node);
3645
}
3746

47+
/** @var UseParser */
48+
private $useParser;
3849
/**
3950
* @property MethodParser
4051
*/

src/Router.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

33
class Router{
4+
45
/**
56
* Finds command by its name
67
*
78
* @param $commandName String
89
* @param $arguments array
9-
* @return Command\CommandInterface
10+
* @return \Command\CommandInterface
1011
*/
1112
public function getCommand($commandName, array $arguments = []){
1213
if ($commandName == 'generate') {
@@ -15,6 +16,8 @@ public function getCommand($commandName, array $arguments = []){
1516
$command = new \Command\UpdateCommand;
1617
} else if($commandName == 'complete'){
1718
$command = new \Command\CompleteCommand;
19+
} else if ($commandName == 'save'){
20+
$command = new \Command\SaveCommand;
1821
} else {
1922
$command = new \Command\ErrorCommand;
2023
}

0 commit comments

Comments
 (0)