Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions fixtures/diagnostics/errors/this_in_function.php

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/diagnostics/errors/this_in_root.php

This file was deleted.

6 changes: 2 additions & 4 deletions src/TreeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ private function collectDiagnostics($node)
// Find the first ancestor that's a class method. Return an error
// if there is none, or if the method is static.
$method = $node->getFirstAncestor(Node\MethodDeclaration::class);
if ($method === null || $method->isStatic()) {
if ($method->isStatic()) {
$this->diagnostics[] = new Diagnostic(
$method === null
? "\$this can only be used in an object context."
: "\$this can not be used in static methods.",
"\$this can not be used in static methods.",
Range::fromNode($node),
null,
DiagnosticSeverity::ERROR,
Expand Down
36 changes: 0 additions & 36 deletions tests/Diagnostics/InvalidThisUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,6 @@ public function testThisInStaticMethodProducesError()
);
}

public function testThisInFunctionProducesError()
{
$diagnostics = $this->collectDiagnostics(
__DIR__ . '/../../fixtures/diagnostics/errors/this_in_function.php'
);

$this->assertCount(1, $diagnostics);
$this->assertDiagnostic(
$diagnostics[0],
'$this can only be used in an object context.',
DiagnosticSeverity::ERROR,
new Range(
new Position(4, 11),
new Position(4, 16)
)
);
}

public function testThisInRoot()
{
$diagnostics = $this->collectDiagnostics(
__DIR__ . '/../../fixtures/diagnostics/errors/this_in_root.php'
);

$this->assertCount(1, $diagnostics);
$this->assertDiagnostic(
$diagnostics[0],
'$this can only be used in an object context.',
DiagnosticSeverity::ERROR,
new Range(
new Position(2, 5),
new Position(2, 10)
)
);
}

public function testThisInMethodProducesNoError()
{
$diagnostics = $this->collectDiagnostics(
Expand Down