Skip to content

Commit 97fe86c

Browse files
authored
Fix BC break introduced in 4.6.3 (#5410)
Fixes #5405 Requires new patch release. This PR reverts changes to the signature of `IssueBuffer::finish()` and introduces separate method to be used to capture `$_SERVER`
1 parent 9d979e3 commit 97fe86c

File tree

8 files changed

+54
-42
lines changed

8 files changed

+54
-42
lines changed

src/Psalm/IssueBuffer.php

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
11
<?php
22
namespace Psalm;
33

4-
use Psalm\Plugin\EventHandler\Event\AfterAnalysisEvent;
5-
use Psalm\Report\PhpStormReport;
6-
use function array_pop;
7-
use function array_search;
8-
use function array_splice;
9-
use function count;
10-
use function debug_print_backtrace;
11-
use function dirname;
12-
use function explode;
13-
use function file_put_contents;
14-
use function fwrite;
15-
use function get_class;
16-
use function is_dir;
17-
use function memory_get_peak_usage;
18-
use function mkdir;
19-
use function microtime;
20-
use function number_format;
21-
use function ob_get_clean;
22-
use function ob_start;
23-
use function sprintf;
244
use Psalm\Internal\Analyzer\IssueData;
255
use Psalm\Internal\Analyzer\ProjectAnalyzer;
266
use Psalm\Internal\ExecutionEnvironment\BuildInfoCollector;
277
use Psalm\Issue\CodeIssue;
288
use Psalm\Issue\UnusedPsalmSuppress;
9+
use Psalm\Plugin\EventHandler\Event\AfterAnalysisEvent;
2910
use Psalm\Report\CheckstyleReport;
3011
use Psalm\Report\CodeClimateReport;
3112
use Psalm\Report\CompactReport;
3213
use Psalm\Report\ConsoleReport;
3314
use Psalm\Report\EmacsReport;
3415
use Psalm\Report\GithubActionsReport;
35-
use Psalm\Report\SarifReport;
3616
use Psalm\Report\JsonReport;
3717
use Psalm\Report\JsonSummaryReport;
3818
use Psalm\Report\JunitReport;
19+
use Psalm\Report\PhpStormReport;
3920
use Psalm\Report\PylintReport;
21+
use Psalm\Report\SarifReport;
4022
use Psalm\Report\SonarqubeReport;
4123
use Psalm\Report\TextReport;
4224
use Psalm\Report\XmlReport;
25+
26+
use function array_merge;
27+
use function array_pop;
28+
use function array_search;
29+
use function array_splice;
30+
use function array_values;
31+
use function count;
32+
use function debug_print_backtrace;
33+
use function dirname;
34+
use function explode;
35+
use function file_put_contents;
36+
use function fwrite;
37+
use function get_class;
38+
use function in_array;
39+
use function is_dir;
40+
use function memory_get_peak_usage;
41+
use function microtime;
42+
use function mkdir;
43+
use function number_format;
44+
use function ob_get_clean;
45+
use function ob_start;
4346
use function sha1;
47+
use function sprintf;
4448
use function str_repeat;
4549
use function str_replace;
4650
use function usort;
47-
use function array_merge;
48-
use function array_values;
49-
use function in_array;
51+
5052
use const DEBUG_BACKTRACE_IGNORE_ARGS;
5153
use const STDERR;
5254

@@ -93,6 +95,9 @@ class IssueBuffer
9395
*/
9496
protected static $used_suppressions = [];
9597

98+
/** @var array<array-key,mixed> */
99+
private static $server = [];
100+
96101
/**
97102
* @param string[] $suppressed_issues
98103
*
@@ -441,7 +446,6 @@ public static function addIssues(array $issues_data): void
441446
*/
442447
public static function finish(
443448
ProjectAnalyzer $project_analyzer,
444-
BuildInfoCollector $build_info_collector,
445449
bool $is_full,
446450
float $start_time,
447451
bool $add_stats = false,
@@ -543,12 +547,13 @@ function (IssueData $d1, IssueData $d2) : int {
543547
}
544548
}
545549

546-
$source_control_info = null;
547-
$build_info = $build_info_collector->collect();
548550

549551
if ($codebase->config->eventDispatcher->after_analysis
550552
|| $codebase->config->eventDispatcher->legacy_after_analysis
551553
) {
554+
$source_control_info = null;
555+
$build_info = (new BuildInfoCollector(self::$server))->collect();
556+
552557
try {
553558
$source_control_info = (new \Psalm\Internal\ExecutionEnvironment\GitInfoCollector())->collect();
554559
} catch (\RuntimeException $e) {
@@ -861,4 +866,13 @@ public static function bubbleUp(CodeIssue $e): void
861866

862867
self::$recorded_issues[self::$recording_level][] = $e;
863868
}
869+
870+
/**
871+
* @internal
872+
* @param array<array-key,mixed> $server
873+
*/
874+
final public static function captureServer(array $server): void
875+
{
876+
self::$server = $server;
877+
}
864878
}

src/psalm-refactor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
require_once __DIR__ . '/command_functions.php';
4343
require_once __DIR__ . '/Psalm/Internal/Composer.php';
4444
require_once __DIR__ . '/Psalm/Internal/IncludeCollector.php';
45-
require_once __DIR__ . '/' . 'Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php';
45+
require_once __DIR__ . '/' . 'Psalm/IssueBuffer.php';
4646

4747
(
4848
/** @param array<int,string> $argv */
@@ -162,7 +162,7 @@ function ($arg) use ($valid_long_options): void {
162162
$vendor_dir = \Psalm\getVendorDir($current_dir);
163163

164164
// capture environment before registering autoloader (it may destroy it)
165-
$build_info_collector = new BuildInfoCollector($_SERVER);
165+
IssueBuffer::captureServer($_SERVER);
166166

167167
$include_collector = new IncludeCollector();
168168
$first_autoloader = $include_collector->runAndCollect(
@@ -309,6 +309,6 @@ function () use ($current_dir, $options, $vendor_dir): ?\Composer\Autoload\Class
309309

310310
$project_analyzer->check($current_dir);
311311

312-
IssueBuffer::finish($project_analyzer, $build_info_collector, false, $start_time);
312+
IssueBuffer::finish($project_analyzer, false, $start_time);
313313
}
314314
)($argv);

src/psalm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Psalm\Internal\Analyzer\ProjectAnalyzer;
77
use Psalm\Internal\Composer;
88
use Psalm\Internal\ErrorHandler;
9-
use Psalm\Internal\ExecutionEnvironment\BuildInfoCollector;
109
use Psalm\Internal\IncludeCollector;
1110
use Psalm\Internal\Provider;
1211
use Psalm\Progress\DebugProgress;
@@ -61,7 +60,7 @@
6160
require_once __DIR__ . '/command_functions.php' ;
6261
require_once __DIR__ . '/Psalm/Internal/Composer.php';
6362
require_once __DIR__ . '/' . 'Psalm/Internal/IncludeCollector.php';
64-
require_once __DIR__ . '/' . 'Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php';
63+
require_once __DIR__ . '/' . 'Psalm/IssueBuffer.php';
6564

6665
(
6766
/**
@@ -284,7 +283,7 @@ function ($arg) use ($valid_long_options, $valid_short_options): void {
284283
$vendor_dir = \Psalm\getVendorDir($current_dir);
285284

286285
// capture environment before registering autoloader (it may destroy it)
287-
$build_info_collector = new BuildInfoCollector($_SERVER);
286+
IssueBuffer::captureServer($_SERVER);
288287

289288
$include_collector = new IncludeCollector();
290289
$first_autoloader = $include_collector->runAndCollect(
@@ -842,7 +841,6 @@ function (array $edges) {
842841
if (!isset($options['i'])) {
843842
IssueBuffer::finish(
844843
$project_analyzer,
845-
$build_info_collector,
846844
!$paths_to_check,
847845
$start_time,
848846
isset($options['stats']),

src/psalter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
require_once __DIR__ . '/command_functions.php';
5454
require_once __DIR__ . '/Psalm/Internal/Composer.php';
5555
require_once __DIR__ . '/Psalm/Internal/IncludeCollector.php';
56-
require_once __DIR__ . '/' . 'Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php';
56+
require_once __DIR__ . '/' . 'Psalm/IssueBuffer.php';
5757

5858
(
5959
/** @param array<int,string> $argv */
@@ -224,7 +224,7 @@ function ($arg) use ($valid_long_options): void {
224224
$vendor_dir = \Psalm\getVendorDir($current_dir);
225225

226226
// capture environment before registering autoloader (it may destroy it)
227-
$build_info_collector = new BuildInfoCollector($_SERVER);
227+
IssueBuffer::captureServer($_SERVER);
228228

229229
$include_collector = new IncludeCollector();
230230
$first_autoloader = $include_collector->runAndCollect(
@@ -515,6 +515,6 @@ function (string $line) : bool {
515515
}
516516
}
517517

518-
IssueBuffer::finish($project_analyzer, $build_info_collector, false, $start_time);
518+
IssueBuffer::finish($project_analyzer, false, $start_time);
519519
}
520520
)($argv);

tests/Config/PluginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ public function testAfterAnalysisHooks(): void
956956

957957
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
958958
ob_start();
959-
\Psalm\IssueBuffer::finish($this->project_analyzer, new BuildInfoCollector([]), true, microtime(true));
959+
\Psalm\IssueBuffer::finish($this->project_analyzer, true, microtime(true));
960960
ob_end_clean();
961961
}
962962

tests/IssueBufferTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testFinishDoesNotCorruptInternalState(): void
8181
$projectAnalzyer->generated_report_options = [];
8282

8383
\ob_start();
84-
IssueBuffer::finish($projectAnalzyer, new BuildInfoCollector([]), false, \microtime(true), false, $baseline);
84+
IssueBuffer::finish($projectAnalzyer, false, \microtime(true), false, $baseline);
8585
$output = \ob_get_clean();
8686
$this->assertStringNotContainsString("ERROR", $output, "all issues baselined");
8787
IssueBuffer::clear();

tests/ProjectCheckerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function testCheckAfterNoChange(): void
157157

158158
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
159159
ob_start();
160-
\Psalm\IssueBuffer::finish($this->project_analyzer, new BuildInfoCollector([]), true, microtime(true));
160+
\Psalm\IssueBuffer::finish($this->project_analyzer, true, microtime(true));
161161
ob_end_clean();
162162

163163
$this->assertSame(
@@ -201,7 +201,7 @@ public function testCheckAfterFileChange(): void
201201

202202
$this->project_analyzer->check('tests/fixtures/DummyProject', true);
203203
ob_start();
204-
\Psalm\IssueBuffer::finish($this->project_analyzer, new BuildInfoCollector([]), true, microtime(true));
204+
\Psalm\IssueBuffer::finish($this->project_analyzer, true, microtime(true));
205205
ob_end_clean();
206206

207207
$this->assertSame(

tests/ReportOutputTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ public function testEmptyReportIfNotError(): void
10531053
);
10541054

10551055
ob_start();
1056-
IssueBuffer::finish($this->project_analyzer, new BuildInfoCollector([]), true, 0);
1056+
IssueBuffer::finish($this->project_analyzer, true, 0);
10571057
ob_end_clean();
10581058
$this->assertFileExists(__DIR__ . '/test-report.json');
10591059
$this->assertSame('[]

0 commit comments

Comments
 (0)