Skip to content

Commit

Permalink
Laravel preset class parentheses (#285)
Browse files Browse the repository at this point in the history
* Add rule to remove empty class parentheses to laravel preset

* Apply new laravel rule on codebase

* Apply new laravel rule to test cases
  • Loading branch information
brdv authored Jul 22, 2024
1 parent 1dbc291 commit 72f3117
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 20 deletions.
12 changes: 6 additions & 6 deletions app/Actions/ElaborateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public function execute($totalFiles, $changes)
protected function displayUsingFormatter($summary, $totalFiles)
{
$reporter = match ($format = $this->input->getOption('format')) {
'checkstyle' => new FixReport\CheckstyleReporter(),
'gitlab' => new FixReport\GitlabReporter(),
'json' => new FixReport\JsonReporter(),
'junit' => new FixReport\JunitReporter(),
'txt' => new FixReport\TextReporter(),
'xml' => new FixReport\XmlReporter(),
'checkstyle' => new FixReport\CheckstyleReporter,
'gitlab' => new FixReport\GitlabReporter,
'json' => new FixReport\JsonReporter,
'junit' => new FixReport\JunitReporter,
'txt' => new FixReport\TextReporter,
'xml' => new FixReport\XmlReporter,
default => abort(1, sprintf('Format [%s] is not supported.', $format)),
};

Expand Down
2 changes: 1 addition & 1 deletion app/Factories/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConfigurationFactory
*/
public static function preset($rules)
{
return (new Config())
return (new Config)
->setParallelConfig(ParallelConfigFactory::detect())
->setFinder(self::finder())
->setRules(array_merge($rules, resolve(ConfigurationJsonRepository::class)->rules()))
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/ConfigurationResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function fromIO($input, $output)
'show-progress' => 'true',
],
Project::path(),
new ToolInfo(),
new ToolInfo,
);

$totalFiles = count(new ArrayIterator(iterator_to_array(
Expand Down
4 changes: 2 additions & 2 deletions app/Output/ProgressOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
protected $input,
protected $output,
) {
$this->symbolsPerLine = (new Terminal())->getWidth() - 4;
$this->symbolsPerLine = (new Terminal)->getWidth() - 4;
}

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ public function handle($event)
{
$symbolsOnCurrentLine = $this->processed % $this->symbolsPerLine;

if ($symbolsOnCurrentLine >= (new Terminal())->getWidth() - 4) {
if ($symbolsOnCurrentLine >= (new Terminal)->getWidth() - 4) {
$symbolsOnCurrentLine = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function boot()
public function register()
{
$this->app->singleton(ErrorsManager::class, function () {
return new ErrorsManager();
return new ErrorsManager;
});

$this->app->singleton(EventDispatcher::class, function () {
return new EventDispatcher();
return new EventDispatcher;
});
}
}
4 changes: 2 additions & 2 deletions app/ValueObjects/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function code()

$exception = $this->payload['source']->getPrevious() ?: $this->payload['source'];

return (new Highlighter())->highlight($content, $exception->getLine());
return (new Highlighter)->highlight($content, $exception->getLine());
}

return $this->diff();
Expand All @@ -98,7 +98,7 @@ public function symbol()
protected function diff()
{
if ($this->payload['diff']) {
$highlighter = new Highlighter();
$highlighter = new Highlighter;
$reflector = new ReflectionClass($highlighter);

$diff = $this->payload['diff'];
Expand Down
4 changes: 4 additions & 0 deletions resources/presets/laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
],
'native_function_casing' => true,
'native_type_declaration_casing' => true,
'new_with_parentheses' => [
'named_class' => false,
'anonymous_class' => false,
],
'no_alias_functions' => true,
'no_alias_language_construct_call' => true,
'no_alternative_syntax' => true,
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/DirtyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
->shouldReceive('dirty')
->once()
->andReturn([
base_path('tests/Fixtures/without-issues/file.php'),
base_path('tests/Fixtures/without-issues-laravel/file.php'),
]);

$this->swap(PathsRepository::class, $paths);
Expand All @@ -28,7 +28,7 @@
->shouldReceive('dirty')
->once()
->andReturn([
base_path('tests/Fixtures/without-issues/file.php'),
base_path('tests/Fixtures/without-issues-laravel/file.php'),
]);

$this->swap(PathsRepository::class, $paths);
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/PresetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

it('uses the laravel preset by default', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/without-issues'),
'path' => base_path('tests/Fixtures/without-issues-laravel'),
]);

expect($statusCode)->toBe(0)
Expand Down Expand Up @@ -34,7 +34,7 @@

it('may use the Laravel preset', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/without-issues'),
'path' => base_path('tests/Fixtures/without-issues-laravel'),
'--preset' => 'laravel',
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/RepairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

it('exits with status 0 without fixes', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/without-issues'),
'path' => base_path('tests/Fixtures/without-issues-laravel'),
'--repair' => true,
'--test' => false,
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

it('may pass', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/without-issues'),
'path' => base_path('tests/Fixtures/without-issues-laravel'),
]);

expect($statusCode)->toBe(0)
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/without-issues-laravel/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$a = new stdClass;

0 comments on commit 72f3117

Please sign in to comment.