Skip to content

Commit

Permalink
Update service providers and fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-chetan committed Apr 3, 2024
1 parent f8a414b commit 873b02c
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 437 deletions.
21 changes: 8 additions & 13 deletions app/Fixer/ClassNotation/CustomOrderedClassElementsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,10 @@ class CustomOrderedClassElementsFixer extends AbstractFixer implements Configura
'phpunit' => null,
];

/**
* @internal
*/
/** @internal */
public const SORT_ALPHA = 'alpha';

/**
* @internal
*/
/** @internal */
public const SORT_NONE = 'none';

private const SUPPORTED_SORT_ALGORITHMS = [
Expand Down Expand Up @@ -263,16 +259,14 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void // @codingS
$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 @@ -359,7 +353,7 @@ private function getElements(Tokens $tokens, int $startIndex): array
for ($i = $startIndex; ; $i++) {
$token = $tokens[$i];

// Class end
// class end
if ($token->equals('}')) {
return $elements;
}
Expand Down Expand Up @@ -483,8 +477,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++); // @codingStandardsIgnoreLine

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, $reviveConfig['exclude']);
});

$this->app->singleton(PathsRepository::class, function () {
return new GitPathsRepository(
Project::path(),
);
});
$this->app->singleton(PathsRepository::class, fn () => new GitPathsRepository(
Project::path(),
));
}
}
4 changes: 2 additions & 2 deletions app/Support/PhpCodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function fix(): int

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

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

return $fix || $lint ? 1 : 0;
Expand Down
33 changes: 17 additions & 16 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,11 +87,6 @@ private function getConfig(): ConfigInterface
{
$config = $this->includeConfig();

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

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

Expand Down Expand Up @@ -121,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."); // @codingStandardsIgnoreLine
}

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));
}
}
18 changes: 12 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
],
"require": {
"php": "^8.2",
"larastan/larastan": "^v2.8.1",
"larastan/larastan": "v2.9.2",
"mrchetan/php_standard": "^4.0.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.49.0",
"friendsofphp/php-cs-fixer": "v3.52.1",
"laravel-zero/framework": "^v10.3",
"laravel/pint": "^v1.13.10",
"laravel/pint": "v1.15.1",
"nunomaduro/termwind": "^v1.15.1",
"pestphp/pest": "^v2.33.4",
"rector/rector": "^0.19.8",
"pestphp/pest": "v2.34.6",
"rector/rector": "^1.0.3",
"spatie/invade": "^1.1.1",
"tightenco/tlint": "^9.2"
"tightenco/tlint": "^v9.3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -53,6 +53,12 @@
"./vendor/squizlabs/php_codesniffer/autoload.php"
]
},
"scripts": {
"lint": "./revive lint",
"fix": "./revive 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 873b02c

Please sign in to comment.