1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Don’t be greedy with lines

This commit is contained in:
Brown 2019-04-17 14:58:13 -04:00
parent f51b073c40
commit b1044b267d
3 changed files with 24 additions and 11 deletions

View File

@ -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();

View File

@ -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(

View File

@ -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 {}
}