Skip to content
Permalink
Browse files

Remove php version from default baseline generation

  • Loading branch information...
muglug committed Jul 11, 2019
1 parent 96ba4ad commit 73b1571bd7727bbd72ff2deb946bdb3fbd8927d7
Showing with 45 additions and 26 deletions.
  1. +33 −22 src/Psalm/ErrorBaseline.php
  2. +4 −0 src/command_functions.php
  3. +5 −2 src/psalm.php
  4. +3 −2 tests/ErrorBaselineTest.php
@@ -52,11 +52,15 @@ function (int $carry, array $existingIssue): int {
*
* @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 @@ public static function read(FileProvider $fileProvider, string $baselineFile): a
*
* @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 @@ public static function update(FileProvider $fileProvider, string $baselineFile,
$groupedIssues = array_filter($existingIssues);
self::writeToFile($fileProvider, $baselineFile, $groupedIssues);
self::writeToFile($fileProvider, $baselineFile, $groupedIssues, $include_php_versions);
return $groupedIssues;
}
@@ -227,27 +235,30 @@ function (array $carry, array $issue): array {
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));
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
)
)));
if ($include_php_versions) {
$extensions = array_merge(get_loaded_extensions(), get_loaded_extensions(true));
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
)
)));
}
foreach ($groupedIssues as $file => $issueTypes) {
$fileNode = $baselineDoc->createElement('file');
@@ -363,12 +363,16 @@ function getPsalmHelpText(): string
--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 @@
'refactor',
'shepherd::',
'no-progress',
'include-php-versions', // used for baseline
];
gc_collect_cycles();
@@ -531,7 +532,8 @@ function ($arg) {
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 @@ function ($arg) {
$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 @@ public function testCreateShouldAggregateIssuesPerFile()
'severity' => 'error',
'selected_text' => 'hardy' . "\n",
],
]);
], false);
$baselineDocument = new \DOMDocument();
$baselineDocument->loadXML($documentContent, LIBXML_NOBLANKS);
@@ -285,7 +285,8 @@ public function testUpdateShouldRemoveExistingIssuesWithoutAddingNewOnes()
$remainingBaseline = ErrorBaseline::update(
$this->fileProvider->reveal(),
$baselineFile,
$newIssues
$newIssues,
false
);
$this->assertSame([

0 comments on commit 73b1571

Please sign in to comment.
You can’t perform that action at this time.