Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 52f07f2

Browse files
authored
Merge pull request #135 from sensiolabs-de/minor-improvments
some minor improvements
2 parents b40ddb4 + 89bc185 commit 52f07f2

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

src/Console/Command/CheckCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function configure()
3838
new InputOption('no-cache', null, InputOption::VALUE_NONE, 'Disable rule set cache'),
3939
new InputOption('cache-dir', null, InputOption::VALUE_REQUIRED, 'Cache directory', '.rules/'),
4040
new InputOption('log-html', null, InputOption::VALUE_REQUIRED, 'Generate HTML report'),
41-
new InputOption('output', null, InputOption::VALUE_REQUIRED, 'Change the output mode'),
41+
new InputOption('output', null, InputOption::VALUE_REQUIRED, 'Change the output mode (default, simple)'),
4242
new InputOption('filter-methods', null, InputOption::VALUE_OPTIONAL, 'Filter methods', ''),
4343
new InputOption('fail', null, InputOption::VALUE_NONE, 'Fails, if any deprecation is detected'),
4444
)

src/TypeGuessing/SymbolTable/Resolver/ArgumentResolver.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ public function __construct(SymbolTable $table)
2525
*/
2626
public function resolveVariableType(Node $node)
2727
{
28-
if ($node instanceof Node\Param) {
29-
if ($node->type instanceof Node\Name) {
30-
$this->table->setSymbol($node->name, $node->type->toString());
31-
}
28+
if ($node instanceof Node\Param && $node->type instanceof Node\Name) {
29+
$this->table->setSymbol($node->name, $node->type->toString());
3230
}
3331
}
3432
}

src/TypeGuessing/SymbolTable/Resolver/VariableAssignResolver.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,38 @@ public function __construct(SymbolTable $table)
3636
*/
3737
public function resolveVariableType(Node $node)
3838
{
39-
if ($node instanceof Node\Expr\Assign) {
40-
// $x = ...
41-
if ($node->var instanceof Node\Expr\Variable) {
42-
// skips variable names like ${$node->nodeName}
43-
if (!is_string($node->var->name)) {
44-
return;
45-
}
46-
47-
// $x = new X();
48-
if ($node->expr instanceof Node\Expr\New_) {
49-
if ($node->expr->class instanceof Node\Name) {
50-
$type = $node->expr->class->toString();
51-
$this->table->setSymbol($node->var->name, $type);
52-
$node->var->setAttribute('guessedType', $type);
53-
}
54-
}
39+
// $x = ...
40+
if (!$node instanceof Node\Expr\Assign
41+
|| !$node->var instanceof Node\Expr\Variable) {
42+
return;
43+
}
5544

56-
// $x = $y;
57-
if ($node->expr instanceof Node\Expr\Variable) {
58-
$type = $this->table->lookUp($node->expr->name)->type();
59-
$node->var->setAttribute('guessedType', $type);
60-
$this->table->setSymbol($node->var->name, $type);
61-
}
45+
// skips variable names like ${$node->nodeName}
46+
if (!is_string($node->var->name)) {
47+
return;
48+
}
6249

63-
// $x = $this->x
64-
if ($node->expr instanceof Node\Expr\PropertyFetch) {
65-
$type = $this->table->lookUpClassProperty($node->expr->name)->type();
66-
$node->var->setAttribute('guessedType', $type);
67-
$this->table->setSymbol($node->var->name, $type);
68-
}
50+
// $x = new X();
51+
if ($node->expr instanceof Node\Expr\New_) {
52+
if ($node->expr->class instanceof Node\Name) {
53+
$type = $node->expr->class->toString();
54+
$this->table->setSymbol($node->var->name, $type);
55+
$node->var->setAttribute('guessedType', $type);
6956
}
7057
}
58+
59+
// $x = $y;
60+
if ($node->expr instanceof Node\Expr\Variable) {
61+
$type = $this->table->lookUp($node->expr->name)->type();
62+
$node->var->setAttribute('guessedType', $type);
63+
$this->table->setSymbol($node->var->name, $type);
64+
}
65+
66+
// $x = $this->x
67+
if ($node->expr instanceof Node\Expr\PropertyFetch) {
68+
$type = $this->table->lookUpClassProperty($node->expr->name)->type();
69+
$node->var->setAttribute('guessedType', $type);
70+
$this->table->setSymbol($node->var->name, $type);
71+
}
7172
}
7273
}

src/TypeGuessing/SymbolTable/Visitor/SymbolTableVariableResolverVisitor.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,17 @@ public function enterNode(Node $node)
5757
}
5858

5959
$this->resolver->resolveVariableType($node);
60-
61-
return;
6260
}
6361

6462
public function leaveNode(Node $node)
6563
{
64+
if ($node instanceof Node\Stmt\Class_ && $node->isAnonymous()) {
65+
return;
66+
}
67+
6668
if ($node instanceof Node\Stmt\Class_
67-
|| $node instanceof Node\Stmt\Interface_
68-
|| $node instanceof Node\Stmt\Trait_) {
69-
if ($node instanceof Node\Stmt\Class_ && $node->isAnonymous()) {
70-
return;
71-
}
69+
|| $node instanceof Node\Stmt\Interface_
70+
|| $node instanceof Node\Stmt\Trait_) {
7271

7372
$this->table->leaveScope();
7473
}

src/Visitor/Usage/FindLanguageDeprecations.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public function enterNode(Node $node)
3434
{
3535
if ($node instanceof Node\Expr\AssignRef && $node->expr instanceof Node\Expr\New_) {
3636
$this->phpFileInfo->addDeprecatedLanguageUsage(
37-
new DeprecatedLanguageUsage('Assigning the return value of new by reference is now deprecated.', 'Since PHP 5.3 use normal assignment instead.', $node->getLine())
37+
new DeprecatedLanguageUsage(
38+
'Assigning the return value of new by reference is now deprecated.',
39+
'Since PHP 5.3 use normal assignment instead.',
40+
$node->getLine()
41+
)
3842
);
3943
}
4044

@@ -51,16 +55,14 @@ public function enterNode(Node $node)
5155
}
5256
}
5357

54-
if ($node instanceof Node\Arg) {
55-
if (true === $node->byRef) {
56-
$this->phpFileInfo->addDeprecatedLanguageUsage(
57-
new DeprecatedLanguageUsage(
58-
'call-time pass-by-reference',
59-
'Since PHP 5.3 and removed in PHP 5.4',
60-
$node->getLine()
61-
)
62-
);
63-
}
58+
if ($node instanceof Node\Arg && true === $node->byRef) {
59+
$this->phpFileInfo->addDeprecatedLanguageUsage(
60+
new DeprecatedLanguageUsage(
61+
'call-time pass-by-reference',
62+
'Since PHP 5.3 and removed in PHP 5.4',
63+
$node->getLine()
64+
)
65+
);
6466
}
6567
}
6668
}

0 commit comments

Comments
 (0)