Skip to content

Commit

Permalink
Merge pull request qossmic#135 from sensiolabs-de/minor-improvments
Browse files Browse the repository at this point in the history
some minor improvements
  • Loading branch information
DavidBadura authored Aug 11, 2017
2 parents b40ddb4 + 89bc185 commit 52f07f2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function configure()
new InputOption('no-cache', null, InputOption::VALUE_NONE, 'Disable rule set cache'),
new InputOption('cache-dir', null, InputOption::VALUE_REQUIRED, 'Cache directory', '.rules/'),
new InputOption('log-html', null, InputOption::VALUE_REQUIRED, 'Generate HTML report'),
new InputOption('output', null, InputOption::VALUE_REQUIRED, 'Change the output mode'),
new InputOption('output', null, InputOption::VALUE_REQUIRED, 'Change the output mode (default, simple)'),
new InputOption('filter-methods', null, InputOption::VALUE_OPTIONAL, 'Filter methods', ''),
new InputOption('fail', null, InputOption::VALUE_NONE, 'Fails, if any deprecation is detected'),
)
Expand Down
6 changes: 2 additions & 4 deletions src/TypeGuessing/SymbolTable/Resolver/ArgumentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public function __construct(SymbolTable $table)
*/
public function resolveVariableType(Node $node)
{
if ($node instanceof Node\Param) {
if ($node->type instanceof Node\Name) {
$this->table->setSymbol($node->name, $node->type->toString());
}
if ($node instanceof Node\Param && $node->type instanceof Node\Name) {
$this->table->setSymbol($node->name, $node->type->toString());
}
}
}
57 changes: 29 additions & 28 deletions src/TypeGuessing/SymbolTable/Resolver/VariableAssignResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,38 @@ public function __construct(SymbolTable $table)
*/
public function resolveVariableType(Node $node)
{
if ($node instanceof Node\Expr\Assign) {
// $x = ...
if ($node->var instanceof Node\Expr\Variable) {
// skips variable names like ${$node->nodeName}
if (!is_string($node->var->name)) {
return;
}

// $x = new X();
if ($node->expr instanceof Node\Expr\New_) {
if ($node->expr->class instanceof Node\Name) {
$type = $node->expr->class->toString();
$this->table->setSymbol($node->var->name, $type);
$node->var->setAttribute('guessedType', $type);
}
}
// $x = ...
if (!$node instanceof Node\Expr\Assign
|| !$node->var instanceof Node\Expr\Variable) {
return;
}

// $x = $y;
if ($node->expr instanceof Node\Expr\Variable) {
$type = $this->table->lookUp($node->expr->name)->type();
$node->var->setAttribute('guessedType', $type);
$this->table->setSymbol($node->var->name, $type);
}
// skips variable names like ${$node->nodeName}
if (!is_string($node->var->name)) {
return;
}

// $x = $this->x
if ($node->expr instanceof Node\Expr\PropertyFetch) {
$type = $this->table->lookUpClassProperty($node->expr->name)->type();
$node->var->setAttribute('guessedType', $type);
$this->table->setSymbol($node->var->name, $type);
}
// $x = new X();
if ($node->expr instanceof Node\Expr\New_) {
if ($node->expr->class instanceof Node\Name) {
$type = $node->expr->class->toString();
$this->table->setSymbol($node->var->name, $type);
$node->var->setAttribute('guessedType', $type);
}
}

// $x = $y;
if ($node->expr instanceof Node\Expr\Variable) {
$type = $this->table->lookUp($node->expr->name)->type();
$node->var->setAttribute('guessedType', $type);
$this->table->setSymbol($node->var->name, $type);
}

// $x = $this->x
if ($node->expr instanceof Node\Expr\PropertyFetch) {
$type = $this->table->lookUpClassProperty($node->expr->name)->type();
$node->var->setAttribute('guessedType', $type);
$this->table->setSymbol($node->var->name, $type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,17 @@ public function enterNode(Node $node)
}

$this->resolver->resolveVariableType($node);

return;
}

public function leaveNode(Node $node)
{
if ($node instanceof Node\Stmt\Class_ && $node->isAnonymous()) {
return;
}

if ($node instanceof Node\Stmt\Class_
|| $node instanceof Node\Stmt\Interface_
|| $node instanceof Node\Stmt\Trait_) {
if ($node instanceof Node\Stmt\Class_ && $node->isAnonymous()) {
return;
}
|| $node instanceof Node\Stmt\Interface_
|| $node instanceof Node\Stmt\Trait_) {

$this->table->leaveScope();
}
Expand Down
24 changes: 13 additions & 11 deletions src/Visitor/Usage/FindLanguageDeprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function enterNode(Node $node)
{
if ($node instanceof Node\Expr\AssignRef && $node->expr instanceof Node\Expr\New_) {
$this->phpFileInfo->addDeprecatedLanguageUsage(
new DeprecatedLanguageUsage('Assigning the return value of new by reference is now deprecated.', 'Since PHP 5.3 use normal assignment instead.', $node->getLine())
new DeprecatedLanguageUsage(
'Assigning the return value of new by reference is now deprecated.',
'Since PHP 5.3 use normal assignment instead.',
$node->getLine()
)
);
}

Expand All @@ -51,16 +55,14 @@ public function enterNode(Node $node)
}
}

if ($node instanceof Node\Arg) {
if (true === $node->byRef) {
$this->phpFileInfo->addDeprecatedLanguageUsage(
new DeprecatedLanguageUsage(
'call-time pass-by-reference',
'Since PHP 5.3 and removed in PHP 5.4',
$node->getLine()
)
);
}
if ($node instanceof Node\Arg && true === $node->byRef) {
$this->phpFileInfo->addDeprecatedLanguageUsage(
new DeprecatedLanguageUsage(
'call-time pass-by-reference',
'Since PHP 5.3 and removed in PHP 5.4',
$node->getLine()
)
);
}
}
}

0 comments on commit 52f07f2

Please sign in to comment.