Skip to content

Commit

Permalink
Cache resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jun 15, 2023
1 parent dad4488 commit 110070a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/EPSG/Import/Codegen.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use PHPCoord\UnitOfMeasure\Rate;
use PHPCoord\UnitOfMeasure\UnitOfMeasure;
use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Config;
use PhpCsFixer\Console\ConfigurationResolver;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\ToolInfo;
Expand Down Expand Up @@ -64,9 +63,17 @@ class Codegen
{
private string $sourceDir;

private ConfigurationResolver $resolver;

public function __construct()
{
$this->sourceDir = dirname(__DIR__, 2);
$this->resolver = new ConfigurationResolver(
require __DIR__ . '/../../../.php-cs-fixer.dist.php',
[],
dirname($this->sourceDir),
new ToolInfo()
);
}

public function updateFileConstants(string $fileName, array $data, string $visibility, array $aliases): void
Expand Down Expand Up @@ -161,23 +168,11 @@ public function updateFileData(string $fileName, array $data): void

public function csFixFile(string $fileName): void
{
/** @var Config $config */
$config = require __DIR__ . '/../../../.php-cs-fixer.dist.php';

$resolver = new ConfigurationResolver(
$config,
[],
dirname($this->sourceDir),
new ToolInfo()
);

$file = new SplFileInfo($fileName);
$old = file_get_contents($fileName);
$fixers = $resolver->getFixers();

$tokens = Tokens::fromCode($old);

foreach ($fixers as $fixer) {
foreach ($this->resolver->getFixers() as $fixer) {
if (
!$fixer instanceof AbstractFixer
&& (!$fixer->supports($file) || !$fixer->isCandidate($tokens))
Expand Down

0 comments on commit 110070a

Please sign in to comment.