mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Remove php version from default baseline generation
This commit is contained in:
parent
96ba4ad7d3
commit
73b1571bd7
@ -52,11 +52,15 @@ class ErrorBaseline
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function create(FileProvider $fileProvider, string $baselineFile, array $issues)
|
||||
{
|
||||
public static function create(
|
||||
FileProvider $fileProvider,
|
||||
string $baselineFile,
|
||||
array $issues,
|
||||
bool $include_php_versions
|
||||
) {
|
||||
$groupedIssues = self::countIssueTypesByFile($issues);
|
||||
|
||||
self::writeToFile($fileProvider, $baselineFile, $groupedIssues);
|
||||
self::writeToFile($fileProvider, $baselineFile, $groupedIssues, $include_php_versions);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,8 +131,12 @@ class ErrorBaseline
|
||||
*
|
||||
* @return array<string,array<string,array{o:int, s:array<int, string>}>>
|
||||
*/
|
||||
public static function update(FileProvider $fileProvider, string $baselineFile, array $issues)
|
||||
{
|
||||
public static function update(
|
||||
FileProvider $fileProvider,
|
||||
string $baselineFile,
|
||||
array $issues,
|
||||
bool $include_php_versions
|
||||
) {
|
||||
$existingIssues = self::read($fileProvider, $baselineFile);
|
||||
$newIssues = self::countIssueTypesByFile($issues);
|
||||
|
||||
@ -159,7 +167,7 @@ class ErrorBaseline
|
||||
|
||||
$groupedIssues = array_filter($existingIssues);
|
||||
|
||||
self::writeToFile($fileProvider, $baselineFile, $groupedIssues);
|
||||
self::writeToFile($fileProvider, $baselineFile, $groupedIssues, $include_php_versions);
|
||||
|
||||
return $groupedIssues;
|
||||
}
|
||||
@ -227,27 +235,30 @@ class ErrorBaseline
|
||||
private static function writeToFile(
|
||||
FileProvider $fileProvider,
|
||||
string $baselineFile,
|
||||
array $groupedIssues
|
||||
array $groupedIssues,
|
||||
bool $include_php_versions
|
||||
) {
|
||||
$baselineDoc = new \DOMDocument('1.0', 'UTF-8');
|
||||
$filesNode = $baselineDoc->createElement('files');
|
||||
$filesNode->setAttribute('psalm-version', PSALM_VERSION);
|
||||
|
||||
$extensions = array_merge(get_loaded_extensions(), get_loaded_extensions(true));
|
||||
if ($include_php_versions) {
|
||||
$extensions = array_merge(get_loaded_extensions(), get_loaded_extensions(true));
|
||||
|
||||
usort($extensions, 'strnatcasecmp');
|
||||
usort($extensions, 'strnatcasecmp');
|
||||
|
||||
$filesNode->setAttribute('php-version', implode(';' . "\n\t", array_merge(
|
||||
[
|
||||
('php:' . PHP_VERSION),
|
||||
],
|
||||
array_map(
|
||||
function (string $extension) : string {
|
||||
return $extension . ':' . phpversion($extension);
|
||||
},
|
||||
$extensions
|
||||
)
|
||||
)));
|
||||
$filesNode->setAttribute('php-version', implode(';' . "\n\t", array_merge(
|
||||
[
|
||||
('php:' . PHP_VERSION),
|
||||
],
|
||||
array_map(
|
||||
function (string $extension) : string {
|
||||
return $extension . ':' . phpversion($extension);
|
||||
},
|
||||
$extensions
|
||||
)
|
||||
)));
|
||||
}
|
||||
|
||||
foreach ($groupedIssues as $file => $issueTypes) {
|
||||
$fileNode = $baselineDoc->createElement('file');
|
||||
|
@ -363,12 +363,16 @@ Options:
|
||||
--set-baseline=PATH
|
||||
Save all current error level issues to a file, to mark them as info in subsequent runs
|
||||
|
||||
Add --include-php-versions to also include a list of PHP extension versions
|
||||
|
||||
--ignore-baseline
|
||||
Ignore the error baseline
|
||||
|
||||
--update-baseline
|
||||
Update the baseline by removing fixed issues. This will not add new issues to the baseline
|
||||
|
||||
Add --include-php-versions to also include a list of PHP extension versions
|
||||
|
||||
--generate-json-map=PATH
|
||||
Generate a map of node references and types in JSON format, saved to the given path.
|
||||
|
||||
|
@ -61,6 +61,7 @@ $valid_long_options = [
|
||||
'refactor',
|
||||
'shepherd::',
|
||||
'no-progress',
|
||||
'include-php-versions', // used for baseline
|
||||
];
|
||||
|
||||
gc_collect_cycles();
|
||||
@ -531,7 +532,8 @@ if (isset($options['set-baseline']) && is_string($options['set-baseline'])) {
|
||||
ErrorBaseline::create(
|
||||
new \Psalm\Internal\Provider\FileProvider,
|
||||
$options['set-baseline'],
|
||||
IssueBuffer::getIssuesData()
|
||||
IssueBuffer::getIssuesData(),
|
||||
isset($options['include-php-versions'])
|
||||
);
|
||||
|
||||
fwrite(STDERR, "Baseline saved to {$options['set-baseline']}.");
|
||||
@ -596,7 +598,8 @@ if (isset($options['update-baseline'])) {
|
||||
$issue_baseline = ErrorBaseline::update(
|
||||
new \Psalm\Internal\Provider\FileProvider,
|
||||
$baselineFile,
|
||||
IssueBuffer::getIssuesData()
|
||||
IssueBuffer::getIssuesData(),
|
||||
isset($options['include-php-versions'])
|
||||
);
|
||||
$total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline);
|
||||
|
||||
|
@ -191,7 +191,7 @@ class ErrorBaselineTest extends TestCase
|
||||
'severity' => 'error',
|
||||
'selected_text' => 'hardy' . "\n",
|
||||
],
|
||||
]);
|
||||
], false);
|
||||
|
||||
$baselineDocument = new \DOMDocument();
|
||||
$baselineDocument->loadXML($documentContent, LIBXML_NOBLANKS);
|
||||
@ -285,7 +285,8 @@ class ErrorBaselineTest extends TestCase
|
||||
$remainingBaseline = ErrorBaseline::update(
|
||||
$this->fileProvider->reveal(),
|
||||
$baselineFile,
|
||||
$newIssues
|
||||
$newIssues,
|
||||
false
|
||||
);
|
||||
|
||||
$this->assertSame([
|
||||
|
Loading…
Reference in New Issue
Block a user