mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Don’t be greedy with lines
This commit is contained in:
parent
f51b073c40
commit
b1044b267d
@ -369,7 +369,7 @@ class Analyzer
|
||||
|
||||
$codebase = $project_analyzer->getCodebase();
|
||||
|
||||
if ($codebase->collect_references
|
||||
if ($codebase->find_unused_code
|
||||
&& ($project_analyzer->full_run || $codebase->find_unused_code === 'always')
|
||||
) {
|
||||
$project_analyzer->checkClassReferences();
|
||||
|
@ -41,21 +41,11 @@ class FileManipulationBuffer
|
||||
|
||||
$file_contents = $codebase->getFileContents($code_location->file_path);
|
||||
|
||||
$removed_lines = false;
|
||||
|
||||
if (($file_contents[$bounds[0] - 1] ?? null) === PHP_EOL
|
||||
&& ($file_contents[$bounds[0] - 2] ?? null) === PHP_EOL
|
||||
) {
|
||||
$removed_lines = true;
|
||||
$bounds[0] -= 2;
|
||||
}
|
||||
|
||||
if (!$removed_lines
|
||||
&& ($file_contents[$bounds[1]] ?? null) === PHP_EOL
|
||||
&& ($file_contents[$bounds[1] + 1] ?? null) === PHP_EOL
|
||||
) {
|
||||
$bounds[1] += 2;
|
||||
}
|
||||
}
|
||||
|
||||
self::add(
|
||||
|
@ -1605,6 +1605,27 @@ class FileManipulationTest extends TestCase
|
||||
['PossiblyUnusedMethod'],
|
||||
true,
|
||||
],
|
||||
'removeAllPossiblyUnusedMethods' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function foo() : void {}
|
||||
|
||||
public function bar() : void {}
|
||||
|
||||
public function bat() : void {}
|
||||
}
|
||||
|
||||
new A();',
|
||||
'<?php
|
||||
class A {
|
||||
|
||||
}
|
||||
|
||||
new A();',
|
||||
'7.1',
|
||||
['PossiblyUnusedMethod'],
|
||||
true,
|
||||
],
|
||||
'dontRemovePossiblyUnusedMethodWithMixedUse' => [
|
||||
'<?php
|
||||
class A {
|
||||
@ -1679,6 +1700,8 @@ class FileManipulationTest extends TestCase
|
||||
(new A)->bar();',
|
||||
'<?php
|
||||
class A {
|
||||
|
||||
|
||||
public function bar() : void {}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user