Skip to content
Permalink
Browse files

using regex to reformat the opening attributes for cleaner git diffs (#…

…1884)

* using regex to reformat the opening attributes for cleaner git diffs

* satisfy phpcs

* preg_replace_callback can return null

* typehint parameter $matches

* Simplify passed docblock

* Change is_null to strict null comparison
  • Loading branch information...
SignpostMarv authored and muglug committed Jul 5, 2019
1 parent 216d8ae commit fe797580e2e722c95171215be6b3cd67d21452b0
Showing with 32 additions and 2 deletions.
  1. +32 −2 src/Psalm/ErrorBaseline.php
@@ -2,6 +2,7 @@
namespace Psalm;
use Psalm\Internal\Provider\FileProvider;
use RuntimeException;
use function array_reduce;
use const LIBXML_NOBLANKS;
use function str_replace;
@@ -16,6 +17,8 @@
use function implode;
use function phpversion;
use function array_map;
use function preg_replace_callback;
use function explode;
class ErrorBaseline
{
@@ -225,7 +228,7 @@ private static function writeToFile(
usort($extensions, 'strnatcasecmp');
$filesNode->setAttribute('php-version', implode('; ', array_merge(
$filesNode->setAttribute('php-version', implode(';' . "\n\t", array_merge(
[
('php:' . phpversion()),
],
@@ -261,6 +264,33 @@ function (string $extension) : string {
$baselineDoc->appendChild($filesNode);
$baselineDoc->formatOutput = true;
$fileProvider->setContents($baselineFile, $baselineDoc->saveXML());
$xml = preg_replace_callback(
'/<files (psalm-version="[^"]+") (?:php-version="(.+)">\n)/',
/**
* @param array<int, string> $matches
*/
function (array $matches) : string {
return
'<files' .
"\n " .
$matches[1] .
"\n" .
' php-version="' .
"\n " .
implode("\n ", explode('&#10;&#9;', $matches[2])) .
"\n" .
' "' .
"\n" .
'>' .
"\n";
},
$baselineDoc->saveXML()
);
if ($xml === null) {
throw new RuntimeException('Failed to reformat opening attributes!');
}
$fileProvider->setContents($baselineFile, $xml);
}
}

0 comments on commit fe79758

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