Skip to content

Instantly share code, notes, and snippets.

@bendavies
Created May 14, 2024 12:31
Show Gist options
  • Save bendavies/944de78000e38a327a5f009471ce4f40 to your computer and use it in GitHub Desktop.
Save bendavies/944de78000e38a327a5f009471ce4f40 to your computer and use it in GitHub Desktop.
<?php
require_once 'vendor/autoload.php';
use Psl\Regex;
use Psl\File;
use Psl\Filesystem;
use Psl\Vec;
$covertedComments = Regex\replace(File\read('phpstan-baseline.php'), '/\/\/ identifier: (.+)/', '\'identifier\' => \'$1\',');
$tempBaseline = Filesystem\create_temporary_file();
File\write($tempBaseline, $covertedComments);
$baseline = include $tempBaseline;
$errors = $baseline['parameters']['ignoreErrors'];
$chunks = Vec\chunk($errors, 100);
Vec\map_with_key($chunks, static function (int $index, array $chunk) {
$filename = 'phpstan-baseline-chunk-' . $index . '.php';
Filesystem\create_file($filename);
$errors = var_export($chunk, true);
$covertedComments = Regex\replace($errors, '/\'identifier\' => \'(.+)\',/', '// identifier: $1');
File\write($filename, '<?php return [\'parameters\' => [\'ignoreErrors\' => ' . $covertedComments . ']];');
});
echo 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment