mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +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
|
* @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);
|
$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>}>>
|
* @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);
|
$existingIssues = self::read($fileProvider, $baselineFile);
|
||||||
$newIssues = self::countIssueTypesByFile($issues);
|
$newIssues = self::countIssueTypesByFile($issues);
|
||||||
|
|
||||||
@ -159,7 +167,7 @@ class ErrorBaseline
|
|||||||
|
|
||||||
$groupedIssues = array_filter($existingIssues);
|
$groupedIssues = array_filter($existingIssues);
|
||||||
|
|
||||||
self::writeToFile($fileProvider, $baselineFile, $groupedIssues);
|
self::writeToFile($fileProvider, $baselineFile, $groupedIssues, $include_php_versions);
|
||||||
|
|
||||||
return $groupedIssues;
|
return $groupedIssues;
|
||||||
}
|
}
|
||||||
@ -227,27 +235,30 @@ class ErrorBaseline
|
|||||||
private static function writeToFile(
|
private static function writeToFile(
|
||||||
FileProvider $fileProvider,
|
FileProvider $fileProvider,
|
||||||
string $baselineFile,
|
string $baselineFile,
|
||||||
array $groupedIssues
|
array $groupedIssues,
|
||||||
|
bool $include_php_versions
|
||||||
) {
|
) {
|
||||||
$baselineDoc = new \DOMDocument('1.0', 'UTF-8');
|
$baselineDoc = new \DOMDocument('1.0', 'UTF-8');
|
||||||
$filesNode = $baselineDoc->createElement('files');
|
$filesNode = $baselineDoc->createElement('files');
|
||||||
$filesNode->setAttribute('psalm-version', PSALM_VERSION);
|
$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(
|
$filesNode->setAttribute('php-version', implode(';' . "\n\t", array_merge(
|
||||||
[
|
[
|
||||||
('php:' . PHP_VERSION),
|
('php:' . PHP_VERSION),
|
||||||
],
|
],
|
||||||
array_map(
|
array_map(
|
||||||
function (string $extension) : string {
|
function (string $extension) : string {
|
||||||
return $extension . ':' . phpversion($extension);
|
return $extension . ':' . phpversion($extension);
|
||||||
},
|
},
|
||||||
$extensions
|
$extensions
|
||||||
)
|
)
|
||||||
)));
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($groupedIssues as $file => $issueTypes) {
|
foreach ($groupedIssues as $file => $issueTypes) {
|
||||||
$fileNode = $baselineDoc->createElement('file');
|
$fileNode = $baselineDoc->createElement('file');
|
||||||
|
@ -363,12 +363,16 @@ Options:
|
|||||||
--set-baseline=PATH
|
--set-baseline=PATH
|
||||||
Save all current error level issues to a file, to mark them as info in subsequent runs
|
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-baseline
|
||||||
Ignore the error baseline
|
Ignore the error baseline
|
||||||
|
|
||||||
--update-baseline
|
--update-baseline
|
||||||
Update the baseline by removing fixed issues. This will not add new issues to the 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-json-map=PATH
|
||||||
Generate a map of node references and types in JSON format, saved to the given 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',
|
'refactor',
|
||||||
'shepherd::',
|
'shepherd::',
|
||||||
'no-progress',
|
'no-progress',
|
||||||
|
'include-php-versions', // used for baseline
|
||||||
];
|
];
|
||||||
|
|
||||||
gc_collect_cycles();
|
gc_collect_cycles();
|
||||||
@ -531,7 +532,8 @@ if (isset($options['set-baseline']) && is_string($options['set-baseline'])) {
|
|||||||
ErrorBaseline::create(
|
ErrorBaseline::create(
|
||||||
new \Psalm\Internal\Provider\FileProvider,
|
new \Psalm\Internal\Provider\FileProvider,
|
||||||
$options['set-baseline'],
|
$options['set-baseline'],
|
||||||
IssueBuffer::getIssuesData()
|
IssueBuffer::getIssuesData(),
|
||||||
|
isset($options['include-php-versions'])
|
||||||
);
|
);
|
||||||
|
|
||||||
fwrite(STDERR, "Baseline saved to {$options['set-baseline']}.");
|
fwrite(STDERR, "Baseline saved to {$options['set-baseline']}.");
|
||||||
@ -596,7 +598,8 @@ if (isset($options['update-baseline'])) {
|
|||||||
$issue_baseline = ErrorBaseline::update(
|
$issue_baseline = ErrorBaseline::update(
|
||||||
new \Psalm\Internal\Provider\FileProvider,
|
new \Psalm\Internal\Provider\FileProvider,
|
||||||
$baselineFile,
|
$baselineFile,
|
||||||
IssueBuffer::getIssuesData()
|
IssueBuffer::getIssuesData(),
|
||||||
|
isset($options['include-php-versions'])
|
||||||
);
|
);
|
||||||
$total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline);
|
$total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline);
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ class ErrorBaselineTest extends TestCase
|
|||||||
'severity' => 'error',
|
'severity' => 'error',
|
||||||
'selected_text' => 'hardy' . "\n",
|
'selected_text' => 'hardy' . "\n",
|
||||||
],
|
],
|
||||||
]);
|
], false);
|
||||||
|
|
||||||
$baselineDocument = new \DOMDocument();
|
$baselineDocument = new \DOMDocument();
|
||||||
$baselineDocument->loadXML($documentContent, LIBXML_NOBLANKS);
|
$baselineDocument->loadXML($documentContent, LIBXML_NOBLANKS);
|
||||||
@ -285,7 +285,8 @@ class ErrorBaselineTest extends TestCase
|
|||||||
$remainingBaseline = ErrorBaseline::update(
|
$remainingBaseline = ErrorBaseline::update(
|
||||||
$this->fileProvider->reveal(),
|
$this->fileProvider->reveal(),
|
||||||
$baselineFile,
|
$baselineFile,
|
||||||
$newIssues
|
$newIssues,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
|
Loading…
Reference in New Issue
Block a user