Skip to content

Commit d2bed47

Browse files
committed
fixed code style and scrutinizer issues
1 parent 9c7085b commit d2bed47

10 files changed

Lines changed: 154 additions & 174 deletions

File tree

src/Complete/Completer/StaticCompleter.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,47 @@
1313
use Entity\Collection\Specification;
1414
use Psr\Log\LoggerInterface;
1515

16-
class StaticCompleter {
17-
public function __construct(LoggerInterface $logger){
16+
class StaticCompleter
17+
{
18+
public function __construct(LoggerInterface $logger)
19+
{
1820
$this->logger = $logger;
1921
}
20-
public function getEntries(Project $project, Context $context){
22+
public function getEntries(Project $project, Context $context)
23+
{
2124
/** @var FQCN $fqcn */
2225
list($fqcn, $isThis) = $context->getData();
23-
$this->logger->addDebug('creating static entries');
24-
if(!$fqcn instanceof FQCN){
26+
$this->logger->debug('creating static entries');
27+
if (!$fqcn instanceof FQCN) {
2528
return [];
2629
}
2730
$index = $project->getIndex();
28-
$this->logger->addDebug('Creating completion for ' . $fqcn->toString());
31+
$this->logger->debug('Creating completion for ' . $fqcn->toString());
2932
$class = $index->findClassByFQCN($fqcn);
30-
if(empty($class)){
33+
if (empty($class)) {
3134
$class = $index->findInterfaceByFQCN($fqcn);
3235
}
33-
if(empty($class)){
36+
if (empty($class)) {
3437
return [];
3538
}
3639
$entries = [];
3740
$spec = new Specification($isThis ? 'private' : 'public', 1);
38-
if($class->methods !== null){
39-
foreach($class->methods->all($spec) AS $method){
41+
if ($class->methods !== null) {
42+
foreach ($class->methods->all($spec) as $method) {
4043
$entry = $this->createEntryForMethod($method);
4144
$entries[$method->name] = $entry;
4245
}
4346
}
44-
if($class instanceof InterfaceData){
47+
if ($class instanceof InterfaceData) {
4548
return $entries;
4649
}
47-
if($class->properties !== null){
48-
foreach($class->properties->all($spec) AS $property){
50+
if ($class->properties !== null) {
51+
foreach ($class->properties->all($spec) as $property) {
4952
$entries[$property->name] = $this->createEntryForProperty($property);
5053
}
5154
}
52-
if($class->constants !== null)
53-
{
54-
foreach($class->constants->all() as $const){
55+
if ($class->constants !== null) {
56+
foreach ($class->constants->all() as $const) {
5557
$entries[$const] = $this->createEntryForConst($const);
5658
}
5759
}
@@ -65,23 +67,26 @@ public function getEntries(Project $project, Context $context){
6567
* @param MethodData $method a method
6668
* @return Entry
6769
*/
68-
protected function createEntryForMethod(MethodData $method){
70+
protected function createEntryForMethod(MethodData $method)
71+
{
6972
return new Entry(
7073
$method->name,
7174
$method->getSignature(),
7275
sprintf("%s\n%s\n", $method->getSignature(), $method->doc)
7376
);
7477
}
7578

76-
protected function createEntryForProperty(ClassProperty $prop){
79+
protected function createEntryForProperty(ClassProperty $prop)
80+
{
7781
$type = $prop->type instanceof FQCN ? $prop->type->toString() : 'mixed';
7882
return new Entry(
7983
'$' . $prop->name,
8084
$type
8185
);
8286
}
8387

84-
protected function createEntryForConst($const){
88+
protected function createEntryForConst($const)
89+
{
8590
return new Entry($const);
8691
}
8792

src/Complete/Completer/UseCompleter.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
use Entity\Completion\Context;
77
use Entity\Completion\Entry;
88

9-
class UseCompleter implements CompleterInterface {
10-
public function getEntries(Project $project, Context $context){
9+
class UseCompleter implements CompleterInterface
10+
{
11+
public function getEntries(Project $project, Context $context)
12+
{
1113
$entries = [];
1214
$postfix = trim($context->getData());
1315
$index = $project->getIndex();
1416
$fqcns = array_merge($index->getClasses(), $index->getInterfaces());
15-
foreach($fqcns as $fqcn => $class){
16-
if(!empty($postfix) && strpos($fqcn, $postfix) === false){
17+
foreach ($fqcns as $fqcn => $class) {
18+
if (!empty($postfix) && strpos($fqcn, $postfix) === false) {
1719
continue;
1820
}
1921
$complete = str_replace($postfix, "", $fqcn);
2022
$entries[] = new Entry(
21-
$complete, '', '',
23+
$complete,
24+
'',
25+
'',
2226
$fqcn
2327
);
2428
}

src/Complete/Resolver/ContextResolver.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,57 @@
1313
use PhpParser\Node\Expr\Variable;
1414
use PhpParser\Node\Name;
1515

16-
class ContextResolver{
16+
class ContextResolver
17+
{
1718
public function __construct(
1819
ErrorFreePhpParser $parser,
1920
NodeTypeResolver $typeResolver,
2021
LoggerInterface $logger,
2122
UseParser $useParser
22-
){
23+
) {
2324
$this->parser = $parser;
2425
$this->typeResolver = $typeResolver;
2526
$this->logger = $logger;
2627
$this->useParser = $useParser;
2728
}
28-
public function getContext($badLine, Index $index, Scope $scope = null){
29-
if(empty($badLine)){
29+
public function getContext($badLine, Index $index, Scope $scope = null)
30+
{
31+
if (empty($badLine)) {
3032
throw new \Exception("Could not define empty line context");
3133
}
32-
if(empty($scope)){
34+
if (empty($scope)) {
3335
$scope = new Scope;
3436
}
3537

3638
$token = $this->getLastToken($badLine);
37-
$this->logger->addDebug(sprintf('Found token \'%s\' with type %s', $token->getSymbol(), $token->getType()));
39+
$this->logger->debug(sprintf(
40+
'Found token \'%s\' with type %s',
41+
$token->getSymbol(),
42+
$token->getType()
43+
));
3844
return $this->createContext($scope, $token, $badLine, $index);
3945
}
4046

4147
/**
4248
* @return Token
4349
*/
44-
protected function getLastToken($badLine){
50+
protected function getLastToken($badLine)
51+
{
4552
try {
46-
$symbols = @token_get_all($this->prepareLine($badLine, $wrapFunctionCall));
47-
}
48-
catch(\Exception $e){
53+
$symbols = @token_get_all($this->prepareLine($badLine, false));
54+
} catch (\Exception $e) {
4955
$symbols = [0,0];
5056
}
5157
$token = null;
5258
array_shift($symbols);
5359
do {
5460
$token = $this->addSymbolForToken(array_pop($symbols), $token);
55-
} while(!$token->isReady() && count($symbols));
61+
} while (!$token->isReady() && count($symbols));
5662
return $token;
5763
}
5864

59-
protected function createContext(Scope $scope, Token $token, $badLine, Index $index){
65+
protected function createContext(Scope $scope, Token $token, $badLine, Index $index)
66+
{
6067
$context = new Context($scope, $token);
6168
$nodes = $this->parser->parse($this->prepareLine($badLine));
6269

@@ -96,18 +103,17 @@ protected function createContext(Scope $scope, Token $token, $badLine, Index $in
96103
return $context;
97104
}
98105

99-
protected function addSymbolForToken($symbol, Token $token = null){
100-
if(is_array($symbol)){
106+
protected function addSymbolForToken($symbol, Token $token = null)
107+
{
108+
if (is_array($symbol)) {
101109
$code = $symbol[0];
102110
$symbol = $symbol[1];
103-
}
104-
else {
111+
} else {
105112
$code = $symbol;
106113
}
107-
if(empty($token)){
114+
if (empty($token)) {
108115
$token = new Token($code, $symbol);
109-
}
110-
else {
116+
} else {
111117
$token->add($code, $symbol);
112118
}
113119
return $token;

src/Complete/Resolver/NodeTypeResolver.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getChainType($node, Index $index, Scope $scope)
9090
$chain = $this->createChain($node);
9191
$block = $chain;
9292
while ($block instanceof Chain) {
93-
$this->logger->addDebug('looking for type of ' . $block->getName());
93+
$this->logger->debug('looking for type of ' . $block->getName());
9494
$event = new TypeResolveEvent($block, $type);
9595
$this->dispatcher->dispatch(self::BLOCK_START, $event);
9696
if ($block->getType() === 'var') {
@@ -109,12 +109,18 @@ public function getChainType($node, Index $index, Scope $scope)
109109
$type = $this->getPropertyType($block->getName(), $type, $index);
110110
} elseif ($block->getType() === 'class') {
111111
$type = $block->getName();
112-
if ($type->getClassName() === 'self'
113-
|| $type->getClassName() === 'static'
114-
) {
115-
$type = $scope->getFQCN();
116-
} elseif ($type->getClassName() === 'parent') {
117-
$type = $this->getParentType($scope->getFQCN(), $index);
112+
if ($type instanceof FQCN) {
113+
if ($type instanceof FQCN && (
114+
$type->getClassName() === 'self'
115+
|| $type->getClassName() === 'static'
116+
)
117+
) {
118+
$type = $scope->getFQCN();
119+
} elseif ($type->getClassName() === 'parent'
120+
&& $scope->getFQCN() instanceof FQCN
121+
) {
122+
$type = $this->getParentType($scope->getFQCN(), $index);
123+
}
118124
}
119125
}
120126
$event = new TypeResolveEvent($block, $type);
@@ -170,38 +176,41 @@ protected function getVarType($name, Scope $scope)
170176
}
171177
return $var->getType();
172178
}
173-
protected function getMethodType($name, FQCN $type, Index $index){
179+
protected function getMethodType($name, FQCN $type, Index $index)
180+
{
174181
$class = $index->findClassByFQCN($type);
175-
if(empty($class)){
182+
if (empty($class)) {
176183
$class = $index->findInterfaceByFQCN($type);
177184
}
178-
if(empty($class)){
185+
if (empty($class)) {
179186
return null;
180187
}
181188
$method = $class->methods->get($name);
182-
if(empty($method)){
189+
if (empty($method)) {
183190
return null;
184191
}
185192
return $method->getReturn();
186193
}
187-
protected function getPropertyType($name, FQCN $type, Index $index){
194+
protected function getPropertyType($name, FQCN $type, Index $index)
195+
{
188196
$class = $index->findClassByFQCN($type);
189-
if(empty($class)){
197+
if (empty($class)) {
190198
return null;
191199
}
192200
$prop = $class->properties->get($name);
193-
if(empty($prop)){
201+
if (empty($prop)) {
194202
return null;
195203
}
196204
return $prop->getType();
197205
}
198-
protected function getParentType(FQCN $type, Index $index){
206+
protected function getParentType(FQCN $type, Index $index)
207+
{
199208
$class = $index->findClassByFQCN($type);
200-
if(empty($class)){
209+
if (empty($class)) {
201210
return null;
202211
}
203212
$parent = $class->getParent();
204-
if(empty($parent)){
213+
if (empty($parent)) {
205214
return null;
206215
}
207216
return $parent->fqcn;

src/Entity/Collection/ConstCollection.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,41 @@
22

33
namespace Entity\Collection;
44

5-
class ConstCollection {
5+
use Entity\Node\ClassData;
66

7-
public function __construct($class){
7+
class ConstCollection
8+
{
9+
public function __construct($class)
10+
{
811
$this->class = $class;
912
$this->map['class'] = 'class';
1013
}
11-
public function add($constant){
14+
public function add($constant)
15+
{
1216
$this->map[$constant] = $constant;
1317
}
14-
public function all(Specification $spec = null){
18+
public function all()
19+
{
1520
$consts = $this->map;
1621
$parent = $this->class->getParent();
17-
if($parent instanceof ClassData){
18-
$props = array_merge(
22+
if ($parent instanceof ClassData) {
23+
$consts = array_merge(
1924
$parent->properties->all(),
2025
$consts
2126
);
2227
}
2328
sort($consts);
2429
return $consts;
2530
}
26-
public function get($propName, $spec = null){
27-
if(array_key_exists($propName, $this->map)){
31+
public function get($propName)
32+
{
33+
if (array_key_exists($propName, $this->map)) {
2834
$const = $this->map[$propName];
2935
return $const;
3036
}
3137
$parent = $this->class->getParent();
32-
if($parent instanceof ClassData){
33-
return $parent->properties->get($name);
38+
if ($parent instanceof ClassData) {
39+
return $parent->properties->get($propName);
3440
}
3541
}
3642

0 commit comments

Comments
 (0)