Skip to content

Commit

Permalink
Merge pull request #142 from tighten/drift/update-rector
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
driftingly authored Mar 30, 2024
2 parents 6d1a598 + bdd67b6 commit e2c5db6
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 362 deletions.
11 changes: 5 additions & 6 deletions app/Fixer/ClassNotation/CustomOrderedClassElementsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,14 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
$i = $tokens->getNextTokenOfKind($i, ['{']);
$elements = $this->getElements($tokens, $i);

if (count($elements) === 0) {
if ($elements === []) {
continue;
}

$sorted = $this->sortElements($elements);
$endIndex = $elements[count($elements) - 1]['end'];

if ($sorted !== $elements) {
$this->sortTokens($tokens, $i, $endIndex, $sorted);
}
$this->sortTokens($tokens, $i, $endIndex, $sorted);

$i = $endIndex;
}
Expand Down Expand Up @@ -472,8 +470,9 @@ private function findElementEnd(Tokens $tokens, int $index): int
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
}

for (++$index; $tokens[$index]->isWhitespace(" \t") || $tokens[$index]->isComment(); $index++);

do {
$index++;
} while ($tokens[$index]->isWhitespace(" \t") || $tokens[$index]->isComment());
$index--;

return $tokens[$index]->isWhitespace() ? $index - 1 : $index;
Expand Down
8 changes: 3 additions & 5 deletions app/Providers/PintServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ public function register()
return new PintConfigurationJsonRepository($config, null, $dusterConfig['exclude']);
});

$this->app->singleton(PathsRepository::class, function () {
return new GitPathsRepository(
Project::path(),
);
});
$this->app->singleton(PathsRepository::class, fn () => new GitPathsRepository(
Project::path(),
));
}
}
2 changes: 1 addition & 1 deletion app/Repositories/PintConfigurationJsonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getPintConfig(): array

/**
* @param array<string, array<int, string>|string> $config
* @return array<string, array<int, string>|string>
* @return array<string, array<int, string>|string>
*/
protected function addPathToConfig(string $path, array $config): array
{
Expand Down
8 changes: 4 additions & 4 deletions app/Support/DusterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
}

/**
* @return array<string, mixed>
* @return array<string, mixed>
*/
public static function loadLocal(): array
{
Expand All @@ -47,7 +47,7 @@ public static function loadLocal(): array

/**
* @param array<string, array<int, string>|string> $config
* @return array<string, array<int, string>|string>
* @return array<string, array<int, string>|string>
*/
public static function scopeConfigPaths(array $config): array
{
Expand All @@ -73,15 +73,15 @@ public static function scopeConfigPaths(array $config): array

/**
* @param array<int, string> $paths
* @return array<int, string>
* @return array<int, string>
*/
public static function expandWildcards(array $paths): array
{
return collect($paths)->flatMap(fn ($path) => static::globPath($path))->values()->toArray();
}

/**
* @return array<int, string>
* @return array<int, string>
*/
public static function globPath(string $path): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Support/PhpCodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function fix(): int

$lint = $this->process('runPHPCS', ['-n', '--report=summary', ...$this->getPaths()]);

if ($lint) {
if ($lint !== 0) {
$this->failure('PHP Code_Sniffer found errors that cannot be fixed automatically.');
}

Expand Down
32 changes: 17 additions & 15 deletions app/Support/PhpCsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function process(): int
{
$output = app()->get(OutputInterface::class);

$resolver = new ConfigurationResolver(
$configurationResolver = new ConfigurationResolver(
$this->getConfig(),
[
'config' => $this->getConfigFilePath(),
Expand All @@ -65,19 +65,19 @@ private function process(): int

$changes = (new Runner(
$this->getConfig()->getFinder(),
$resolver->getFixers(),
$resolver->getDiffer(),
$configurationResolver->getFixers(),
$configurationResolver->getDiffer(),
app()->get(EventDispatcher::class),
app()->get(ErrorsManager::class),
$resolver->getLinter(),
$resolver->isDryRun(),
$resolver->getCacheManager(),
$resolver->getDirectory(),
$resolver->shouldStopOnViolation()
$configurationResolver->getLinter(),
$configurationResolver->isDryRun(),
$configurationResolver->getCacheManager(),
$configurationResolver->getDirectory(),
$configurationResolver->shouldStopOnViolation()
))->fix();

$totalFiles = count(new ArrayIterator(iterator_to_array(
$resolver->getFinder(),
$configurationResolver->getFinder(),
)));

return app()->get(ElaborateSummary::class)->execute($totalFiles, $changes);
Expand All @@ -87,10 +87,6 @@ private function getConfig(): ConfigInterface
{
$config = $this->includeConfig();

if (! $config instanceof ConfigInterface) {
throw new InvalidConfigurationException("The PHP CS Fixer config file does not return a 'PhpCsFixer\ConfigInterface' instance.");
}

return $config->setFinder($this->updateFinder($config->getFinder()));
}

Expand Down Expand Up @@ -120,9 +116,15 @@ private function updateFinder(Finder $finder): Finder
return $finder;
}

private function includeConfig(): Config
private function includeConfig(): ConfigInterface
{
return include $this->getConfigFilePath();
$config = include $this->getConfigFilePath();

if (! $config instanceof ConfigInterface) {
throw new InvalidConfigurationException("The PHP CS Fixer config file does not return a 'PhpCsFixer\ConfigInterface' instance.");
}

return $config;
}

private function getConfigFilePath(): string
Expand Down
4 changes: 2 additions & 2 deletions app/Support/Pint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function fix(): int

private function process(): int
{
$pint = new DefaultCommand;
$defaultCommand = new DefaultCommand;

return $pint->handle(resolve(FixCode::class), resolve(ElaborateSummary::class));
return $defaultCommand->handle(resolve(FixCode::class), resolve(ElaborateSummary::class));
}
}
Binary file modified builds/duster
Binary file not shown.
24 changes: 15 additions & 9 deletions composer-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"php": "^8.1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.21.1",
"laravel-zero/framework": "^10.1.1",
"laravel/pint": "^v1.11.0",
"friendsofphp/php-cs-fixer": "^3.49",
"larastan/larastan": "^2.7",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest": "^1.21.3",
"rector/rector": "^0.15.10",
"laravel-zero/framework": "^10.3",
"laravel/pint": "^1.13",
"nunomaduro/termwind": "^1.15",
"pestphp/pest": "^1.23",
"rector/rector": "^1.0",
"spatie/invade": "^1.1",
"spatie/laravel-ray": "^1.31",
"squizlabs/php_codesniffer": "^3.7",
"tightenco/tlint": "^9.0"
"spatie/laravel-ray": "^1.33",
"squizlabs/php_codesniffer": "^3.8",
"tightenco/tlint": "^9.2"
},
"autoload": {
"psr-4": {
Expand All @@ -30,6 +30,12 @@
"./vendor/squizlabs/php_codesniffer/autoload.php"
]
},
"scripts": {
"lint": "./duster lint",
"fix": "./duster fix",
"rector-dry-run": "vendor/bin/rector process --dry-run --ansi",
"rector": "vendor/bin/rector process --ansi"
},
"config": {
"preferred-install": {
"laravel/pint": "source",
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"php": "^8.1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.46",
"friendsofphp/php-cs-fixer": "^3.49",
"laravel-zero/framework": "^10.3",
"laravel/pint": "^1.13",
"nunomaduro/termwind": "^1.15",
Expand All @@ -56,6 +56,12 @@
"./vendor/squizlabs/php_codesniffer/autoload.php"
]
},
"scripts": {
"lint": "./duster lint",
"fix": "./duster fix",
"rector-dry-run": "vendor/bin/rector process --dry-run --ansi",
"rector": "vendor/bin/rector process --ansi"
},
"config": {
"preferred-install": {
"laravel/pint": "source",
Expand Down
Loading

0 comments on commit e2c5db6

Please sign in to comment.