2018-10-26 22:17:15 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests\FileUpdates;
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\FileAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
|
|
|
use Psalm\Internal\Provider\Providers;
|
2018-10-26 22:17:15 +02:00
|
|
|
use Psalm\Tests\TestConfig;
|
2018-11-12 16:57:05 +01:00
|
|
|
use Psalm\Tests\Internal\Provider;
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
class TemporaryUpdateTest extends \Psalm\Tests\TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
FileAnalyzer::clearCache();
|
2018-10-26 22:17:15 +02:00
|
|
|
|
2018-11-12 16:57:05 +01:00
|
|
|
$this->file_provider = new \Psalm\Tests\Internal\Provider\FakeFileProvider();
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
$config = new TestConfig();
|
|
|
|
$config->throw_exception = false;
|
|
|
|
|
|
|
|
$providers = new Providers(
|
|
|
|
$this->file_provider,
|
2018-11-12 16:57:05 +01:00
|
|
|
new \Psalm\Tests\Internal\Provider\ParserInstanceCacheProvider(),
|
2018-10-26 22:17:15 +02:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
new Provider\FakeFileReferenceCacheProvider()
|
|
|
|
);
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = new ProjectAnalyzer(
|
2018-10-26 22:17:15 +02:00
|
|
|
$config,
|
|
|
|
$providers,
|
|
|
|
false,
|
|
|
|
true,
|
2018-11-06 03:57:36 +01:00
|
|
|
ProjectAnalyzer::TYPE_CONSOLE,
|
2018-10-26 22:17:15 +02:00
|
|
|
1,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer->getCodebase()->infer_types_from_usage = true;
|
2018-10-26 22:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestErrorFix
|
|
|
|
*
|
|
|
|
* @param array<int, array<string, string>> $file_stages
|
|
|
|
* @param array<int, int> $error_positions
|
|
|
|
* @param array<string, string> $error_levels
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testErrorFix(
|
|
|
|
array $file_stages,
|
|
|
|
array $error_positions,
|
|
|
|
array $error_levels = []
|
|
|
|
) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer->getCodebase()->diff_methods = true;
|
2018-10-26 22:17:15 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase = $this->project_analyzer->getCodebase();
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
$config = $codebase->config;
|
|
|
|
|
|
|
|
foreach ($error_levels as $error_type => $error_level) {
|
|
|
|
$config->setCustomErrorLevel($error_type, $error_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
$start_files = array_shift($file_stages);
|
|
|
|
|
|
|
|
// first batch
|
|
|
|
foreach ($start_files as $file_path => $contents) {
|
|
|
|
$this->file_provider->registerFile($file_path, $contents);
|
|
|
|
$codebase->file_provider->openFile($file_path);
|
|
|
|
$codebase->addFilesToAnalyze([$file_path => $file_path]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$codebase->scanFiles();
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
$data = \Psalm\IssueBuffer::clear();
|
|
|
|
|
|
|
|
$found_positions = array_map(
|
|
|
|
/** @param array{from: int} $a */
|
|
|
|
function (array $a) : int {
|
|
|
|
return $a['from'];
|
|
|
|
},
|
|
|
|
$data
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame($error_positions[0], $found_positions);
|
|
|
|
|
|
|
|
foreach ($file_stages as $i => $file_stage) {
|
|
|
|
foreach ($file_stage as $file_path => $contents) {
|
|
|
|
$codebase->addTemporaryFileChanges(
|
|
|
|
$file_path,
|
2018-11-09 16:41:51 +01:00
|
|
|
$contents
|
2018-10-26 22:17:15 +02:00
|
|
|
);
|
2018-11-09 16:41:51 +01:00
|
|
|
$codebase->invalidateInformationForFile($file_path);
|
|
|
|
$codebase->scanTemporaryFileChanges($file_path);
|
2018-10-26 22:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($file_stage as $file_path => $contents) {
|
|
|
|
$codebase->addFilesToAnalyze([$file_path => $file_path]);
|
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
$data = \Psalm\IssueBuffer::clear();
|
|
|
|
|
|
|
|
$found_positions = array_map(
|
|
|
|
/** @param array{from: int} $a */
|
|
|
|
function (array $a) : int {
|
|
|
|
return $a['from'];
|
|
|
|
},
|
|
|
|
$data
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame($error_positions[$i + 1], $found_positions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function providerTestErrorFix()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'fixMissingColonSyntaxError' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
$a = 5;
|
|
|
|
echo $a;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
$a = 5
|
|
|
|
echo $a;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
$a = 5;
|
|
|
|
echo $a;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [230], []],
|
|
|
|
],
|
|
|
|
'addReturnTypesToSingleMethod' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() {
|
|
|
|
$a = $_GET["foo"];
|
|
|
|
return $this->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() {
|
|
|
|
$a = $_GET["foo"];
|
|
|
|
return $this->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
$a = $_GET["foo"];
|
|
|
|
return $this->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[136, 317, 273], [323, 279], [329]],
|
|
|
|
],
|
|
|
|
'addSpaceAffectingOffsets' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
$a = 5;
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
$a = $_GET["foo"];
|
|
|
|
return $this->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
$a = 5;
|
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
$a = $_GET["foo"];
|
|
|
|
return $this->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
$a = 5;
|
|
|
|
|
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
$a = $_GET["foo"];
|
|
|
|
return $this->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[373], [374], [375]],
|
|
|
|
[
|
|
|
|
'MixedAssignment' => \Psalm\Config::REPORT_INFO,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'fixReturnType' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : string {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : int {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[189, 144, 332, 290], [338, 296], []],
|
|
|
|
[
|
|
|
|
'MissingReturnType' => \Psalm\Config::REPORT_INFO,
|
|
|
|
]
|
|
|
|
],
|
2018-11-01 21:04:37 +01:00
|
|
|
'resolveNamesInDifferentFunction' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param string (A::class | B::class)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function foo($a) {
|
|
|
|
return A::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param string $a - one of (A::class | B::class)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function foo($a) {
|
|
|
|
return A::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[333], []],
|
|
|
|
[
|
|
|
|
'InvalidDocblock' => \Psalm\Config::REPORT_INFO,
|
|
|
|
]
|
|
|
|
],
|
2018-10-26 22:17:15 +02:00
|
|
|
'bridgeStatements' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : int {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[136, 273], [279], [186, 144]],
|
|
|
|
[
|
|
|
|
'MissingReturnType' => \Psalm\Config::REPORT_INFO,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'colonReturnType' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bar() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
2018-11-01 22:03:08 +01:00
|
|
|
'error_positions' => [[136, 273], [144, 136, 275]],
|
2018-10-26 22:17:15 +02:00
|
|
|
[
|
|
|
|
'MissingReturnType' => \Psalm\Config::REPORT_INFO,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'noChangeJustWeirdDocblocks' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public $aB = 5;
|
|
|
|
|
|
|
|
const F = 1;
|
|
|
|
|
|
|
|
public function bat() : void {
|
|
|
|
$a = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* another
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function foo() {
|
|
|
|
$a = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is one line
|
|
|
|
// this is another
|
|
|
|
public function bar() : void {
|
|
|
|
$b = 1;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public $aB = 5;
|
|
|
|
|
|
|
|
const F = 1;
|
|
|
|
|
|
|
|
public function bat() : void {
|
|
|
|
$a = 1;
|
|
|
|
$b = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* another
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function foo() {
|
|
|
|
$a = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is one line
|
|
|
|
// this is another
|
|
|
|
public function bar() : void {
|
|
|
|
$b = 1;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
2018-11-09 06:59:13 +01:00
|
|
|
'error_positions' => [[127], [127]],
|
2018-10-26 22:17:15 +02:00
|
|
|
],
|
2018-10-27 05:04:38 +02:00
|
|
|
'removeUseShouldInvalidate' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [197]],
|
|
|
|
],
|
|
|
|
'removeGroupUseShouldInvalidate' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
use PhpParser\{Error};
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new Error("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new Error("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [197]],
|
|
|
|
],
|
|
|
|
'removeUseWithAliasShouldInvalidate' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
use Exception as E;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [197]],
|
|
|
|
],
|
|
|
|
'removeGroupUseWithAliasShouldInvalidate' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
use PhpParser\{Error as E};
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [197]],
|
|
|
|
],
|
|
|
|
'removeUseShouldInvalidateNoNamespace' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
use PhpParser\Node\Name;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
new Name("Martin");
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
new Name("Martin");
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [147]],
|
|
|
|
],
|
|
|
|
'removeGroupUseShouldInvalidateNoNamespace' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
use PhpParser\{Error};
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new Error("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new Error("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [197]],
|
|
|
|
],
|
|
|
|
'removeUseWithAliasShouldInvalidateNoNamespace' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
use Exception as E;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [153]],
|
|
|
|
],
|
|
|
|
'removeGroupUseWithAliasShouldInvalidateNoNamespace' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
use PhpParser\{Error as E};
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
throw new E("bad", 5);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[], [197]],
|
|
|
|
],
|
2018-10-30 23:58:22 +01:00
|
|
|
'addUseShouldValidate' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
2018-11-01 21:04:37 +01:00
|
|
|
throw new E();
|
2018-10-30 23:58:22 +01:00
|
|
|
}
|
|
|
|
}',
|
2018-11-01 21:04:37 +01:00
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'E.php' => '<?php
|
|
|
|
namespace Bar;
|
|
|
|
|
|
|
|
class E extends \Exception {}',
|
2018-10-30 23:58:22 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
2018-11-01 21:04:37 +01:00
|
|
|
use Bar\E;
|
2018-10-30 23:58:22 +01:00
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
2018-11-01 21:04:37 +01:00
|
|
|
throw new E();
|
2018-10-30 23:58:22 +01:00
|
|
|
}
|
|
|
|
}',
|
2018-11-01 21:04:37 +01:00
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'E.php' => '<?php
|
|
|
|
namespace Bar;
|
|
|
|
|
|
|
|
class E extends \Exception {}',
|
2018-10-30 23:58:22 +01:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[197], []],
|
|
|
|
],
|
2018-11-16 00:09:57 +01:00
|
|
|
'fixMissingProperty' => [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public function foo() : void {
|
|
|
|
echo $this->bar;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
class A {
|
|
|
|
/** @var string */
|
|
|
|
private $bar = "hello";
|
|
|
|
public function foo() : void {
|
|
|
|
echo $this->bar;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'error_positions' => [[192, 192], []],
|
|
|
|
],
|
2018-10-26 22:17:15 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|