1
0
Fork 0

refactor(scope): remove special-case handling of $this

pull/609/head
Declspeck 2018-02-24 20:38:49 +02:00
parent 7dd0f10564
commit a8829a9b44
No known key found for this signature in database
GPG Key ID: F0417663122A2189
5 changed files with 7 additions and 19 deletions

View File

@ -201,9 +201,6 @@ class CompletionProvider
$prefixLen = strlen($namePrefix);
$scope = getScopeAtNode($this->definitionResolver, $node);
$variables = $scope->variables;
if ($scope->thisVariable !== null) {
$variables['this'] = $scope->thisVariable;
}
foreach ($variables as $name => $var) {
if (substr($name, 0, $prefixLen) !== $namePrefix) {
continue;

View File

@ -563,9 +563,6 @@ class DefinitionResolver
// $myVariable -> type of corresponding assignment expression
if ($expr instanceof Node\Expression\Variable || $expr instanceof Node\UseVariableName) {
$name = $expr->getName();
if ($name === 'this') {
return $scope->thisVariable === null ? new Types\Mixed_ : $scope->thisVariable->type;
}
return isset($scope->variables[$name])
? $scope->variables[$name]->type
: new Types\Mixed_;

View File

@ -9,13 +9,6 @@ use Microsoft\PhpParser\Node\QualifiedName;
*/
class Scope
{
/**
* @var Variable|null $this
*
* Note that this will be set when a class is entered. It is unset again when entering a static function.
*/
public $thisVariable;
/**
* @var Variable|null $this, except also set in static contexts.
*/

View File

@ -102,8 +102,8 @@ class TreeTraverser
$childScope->currentClassLikeVariable = $scope->currentClassLikeVariable;
$childScope->resolvedNameCache = $scope->resolvedNameCache;
$isStatic = $node instanceof Node\MethodDeclaration ? $node->isStatic() : !empty($node->staticModifier);
if (!$isStatic) {
$childScope->thisVariable = $scope->thisVariable;
if (!$isStatic && isset($scope->variables['this'])) {
$childScope->variables['this'] = $scope->variables['this'];
}
if ($node->parameters !== null) {
@ -138,11 +138,12 @@ class TreeTraverser
) {
$childScope = new Scope;
$childScope->resolvedNameCache = $scope->resolvedNameCache;
$childScope->thisVariable = new Variable(
$thisVar = new Variable(
new Types\Object_(new Fqsen('\\' . (string)$node->getNamespacedName())),
$node
);
$childScope->currentClassLikeVariable = $childScope->thisVariable;
$childScope->variables['this'] = $thisVar;
$childScope->currentClassLikeVariable = $thisVar;
return $childScope;
}

View File

@ -106,8 +106,8 @@ class TreeAnalyzer
}
// Check for invalid usage of $this.
if ($scope->thisVariable === null &&
$node instanceof Node\Expression\Variable &&
if ($node instanceof Node\Expression\Variable &&
!isset($scope->variables['this']) &&
$node->getName() === 'this'
) {
$this->diagnostics[] = new Diagnostic(