Skip to content

Commit

Permalink
Fix BC break introduced in 4.6.3 (#5410)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
weirdan authored Mar 16, 2021
1 parent 9d979e3 commit 97fe86c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 42 deletions.
68 changes: 41 additions & 27 deletions src/Psalm/IssueBuffer.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
<?php
namespace Psalm;

use Psalm\Plugin\EventHandler\Event\AfterAnalysisEvent;
use Psalm\Report\PhpStormReport;
use function array_pop;
use function array_search;
use function array_splice;
use function count;
use function debug_print_backtrace;
use function dirname;
use function explode;
use function file_put_contents;
use function fwrite;
use function get_class;
use function is_dir;
use function memory_get_peak_usage;
use function mkdir;
use function microtime;
use function number_format;
use function ob_get_clean;
use function ob_start;
use function sprintf;
use Psalm\Internal\Analyzer\IssueData;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\ExecutionEnvironment\BuildInfoCollector;
use Psalm\Issue\CodeIssue;
use Psalm\Issue\UnusedPsalmSuppress;
use Psalm\Plugin\EventHandler\Event\AfterAnalysisEvent;
use Psalm\Report\CheckstyleReport;
use Psalm\Report\CodeClimateReport;
use Psalm\Report\CompactReport;
use Psalm\Report\ConsoleReport;
use Psalm\Report\EmacsReport;
use Psalm\Report\GithubActionsReport;
use Psalm\Report\SarifReport;
use Psalm\Report\JsonReport;
use Psalm\Report\JsonSummaryReport;
use Psalm\Report\JunitReport;
use Psalm\Report\PhpStormReport;
use Psalm\Report\PylintReport;
use Psalm\Report\SarifReport;
use Psalm\Report\SonarqubeReport;
use Psalm\Report\TextReport;
use Psalm\Report\XmlReport;

use function array_merge;
use function array_pop;
use function array_search;
use function array_splice;
use function array_values;
use function count;
use function debug_print_backtrace;
use function dirname;
use function explode;
use function file_put_contents;
use function fwrite;
use function get_class;
use function in_array;
use function is_dir;
use function memory_get_peak_usage;
use function microtime;
use function mkdir;
use function number_format;
use function ob_get_clean;
use function ob_start;
use function sha1;
use function sprintf;
use function str_repeat;
use function str_replace;
use function usort;
use function array_merge;
use function array_values;
use function in_array;

use const DEBUG_BACKTRACE_IGNORE_ARGS;
use const STDERR;

Expand Down Expand Up @@ -93,6 +95,9 @@ class IssueBuffer
*/
protected static $used_suppressions = [];

/** @var array<array-key,mixed> */
private static $server = [];

/**
* @param string[] $suppressed_issues
*
Expand Down Expand Up @@ -441,7 +446,6 @@ public static function addIssues(array $issues_data): void
*/
public static function finish(
ProjectAnalyzer $project_analyzer,
BuildInfoCollector $build_info_collector,
bool $is_full,
float $start_time,
bool $add_stats = false,
Expand Down Expand Up @@ -543,12 +547,13 @@ function (IssueData $d1, IssueData $d2) : int {
}
}

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

if ($codebase->config->eventDispatcher->after_analysis
|| $codebase->config->eventDispatcher->legacy_after_analysis
) {
$source_control_info = null;
$build_info = (new BuildInfoCollector(self::$server))->collect();

try {
$source_control_info = (new \Psalm\Internal\ExecutionEnvironment\GitInfoCollector())->collect();
} catch (\RuntimeException $e) {
Expand Down Expand Up @@ -861,4 +866,13 @@ public static function bubbleUp(CodeIssue $e): void

self::$recorded_issues[self::$recording_level][] = $e;
}

/**
* @internal
* @param array<array-key,mixed> $server
*/
final public static function captureServer(array $server): void
{
self::$server = $server;
}
}
6 changes: 3 additions & 3 deletions src/psalm-refactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
require_once __DIR__ . '/command_functions.php';
require_once __DIR__ . '/Psalm/Internal/Composer.php';
require_once __DIR__ . '/Psalm/Internal/IncludeCollector.php';
require_once __DIR__ . '/' . 'Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php';
require_once __DIR__ . '/' . 'Psalm/IssueBuffer.php';

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

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

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

$project_analyzer->check($current_dir);

IssueBuffer::finish($project_analyzer, $build_info_collector, false, $start_time);
IssueBuffer::finish($project_analyzer, false, $start_time);
}
)($argv);
6 changes: 2 additions & 4 deletions src/psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Composer;
use Psalm\Internal\ErrorHandler;
use Psalm\Internal\ExecutionEnvironment\BuildInfoCollector;
use Psalm\Internal\IncludeCollector;
use Psalm\Internal\Provider;
use Psalm\Progress\DebugProgress;
Expand Down Expand Up @@ -61,7 +60,7 @@
require_once __DIR__ . '/command_functions.php' ;
require_once __DIR__ . '/Psalm/Internal/Composer.php';
require_once __DIR__ . '/' . 'Psalm/Internal/IncludeCollector.php';
require_once __DIR__ . '/' . 'Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php';
require_once __DIR__ . '/' . 'Psalm/IssueBuffer.php';

(
/**
Expand Down Expand Up @@ -284,7 +283,7 @@ function ($arg) use ($valid_long_options, $valid_short_options): void {
$vendor_dir = \Psalm\getVendorDir($current_dir);

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

$include_collector = new IncludeCollector();
$first_autoloader = $include_collector->runAndCollect(
Expand Down Expand Up @@ -842,7 +841,6 @@ function (array $edges) {
if (!isset($options['i'])) {
IssueBuffer::finish(
$project_analyzer,
$build_info_collector,
!$paths_to_check,
$start_time,
isset($options['stats']),
Expand Down
6 changes: 3 additions & 3 deletions src/psalter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
require_once __DIR__ . '/command_functions.php';
require_once __DIR__ . '/Psalm/Internal/Composer.php';
require_once __DIR__ . '/Psalm/Internal/IncludeCollector.php';
require_once __DIR__ . '/' . 'Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php';
require_once __DIR__ . '/' . 'Psalm/IssueBuffer.php';

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

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

$include_collector = new IncludeCollector();
$first_autoloader = $include_collector->runAndCollect(
Expand Down Expand Up @@ -515,6 +515,6 @@ function (string $line) : bool {
}
}

IssueBuffer::finish($project_analyzer, $build_info_collector, false, $start_time);
IssueBuffer::finish($project_analyzer, false, $start_time);
}
)($argv);
2 changes: 1 addition & 1 deletion tests/Config/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public function testAfterAnalysisHooks(): void

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

Expand Down
2 changes: 1 addition & 1 deletion tests/IssueBufferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testFinishDoesNotCorruptInternalState(): void
$projectAnalzyer->generated_report_options = [];

\ob_start();
IssueBuffer::finish($projectAnalzyer, new BuildInfoCollector([]), false, \microtime(true), false, $baseline);
IssueBuffer::finish($projectAnalzyer, false, \microtime(true), false, $baseline);
$output = \ob_get_clean();
$this->assertStringNotContainsString("ERROR", $output, "all issues baselined");
IssueBuffer::clear();
Expand Down
4 changes: 2 additions & 2 deletions tests/ProjectCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function testCheckAfterNoChange(): void

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

$this->assertSame(
Expand Down Expand Up @@ -201,7 +201,7 @@ public function testCheckAfterFileChange(): void

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

$this->assertSame(
Expand Down
2 changes: 1 addition & 1 deletion tests/ReportOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ public function testEmptyReportIfNotError(): void
);

ob_start();
IssueBuffer::finish($this->project_analyzer, new BuildInfoCollector([]), true, 0);
IssueBuffer::finish($this->project_analyzer, true, 0);
ob_end_clean();
$this->assertFileExists(__DIR__ . '/test-report.json');
$this->assertSame('[]
Expand Down

0 comments on commit 97fe86c

Please sign in to comment.