Skip to content

Commit

Permalink
Merge pull request #244 from TheDragonCode/5.x
Browse files Browse the repository at this point in the history
Added `declare_strict_types` rule
  • Loading branch information
andrey-helldar authored Feb 28, 2025
2 parents ef7d575 + 9628e92 commit 784218a
Show file tree
Hide file tree
Showing 32 changed files with 66 additions and 10 deletions.
13 changes: 4 additions & 9 deletions app/Factories/ConfigurationResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function fromIO(InputInterface $input, OutputInterface $output): a

$preset = $configuration->preset();

abort_unless(in_array($preset, static::presets()), 1, 'Preset not found.');
abort_unless(in_array($preset, static::presets(), true), 1, 'Preset not found.');

$resolver = static::resolver($input, $output, $path, $configuration, $preset);

Expand All @@ -58,11 +58,11 @@ protected static function resolver(
array $path,
ConfigurationJsonRepository $configuration,
string $preset,
) {
): ConfigurationResolver {
return new ConfigurationResolver(
new Config('default'),
[
'allow-risky' => static::allowRisky($input),
'allow-risky' => 'yes',
'config' => implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 2),
'resources',
Expand Down Expand Up @@ -98,16 +98,11 @@ protected static function paths(InputInterface $input): array
return Project::paths($input);
}

protected static function configuration()
protected static function configuration(): ConfigurationJsonRepository
{
return resolve(ConfigurationJsonRepository::class);
}

protected static function allowRisky(InputInterface $input): string
{
return $input->getOption('risky') ? 'yes' : 'no';
}

protected static function presets(): array
{
return PhpVersion::values();
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace DragonCode\CodeStyler\Providers;

use App\Repositories\ConfigurationJsonRepository as ConfigurationJsonRepositoryConcern;
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Create The Application
Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use DragonCode\CodeStyler\Providers\ActionsServiceProvider;
use DragonCode\CodeStyler\Providers\AppServiceProvider;
use DragonCode\CodeStyler\Providers\CommandsServiceProvider;
Expand Down
2 changes: 2 additions & 0 deletions config/commands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use DragonCode\CodeStyler\Commands\DefaultCommand;
use DragonCode\CodeStyler\Commands\DependabotCommand;
use DragonCode\CodeStyler\Commands\EditorConfigCommand;
Expand Down
3 changes: 2 additions & 1 deletion resources/presets/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
'position' => 'next_line',
],

'declare_parentheses' => true,
'declare_parentheses' => true,
'declare_strict_types' => true,

'escape_implicit_backslashes' => [
'double_quoted' => true,
Expand Down
2 changes: 2 additions & 0 deletions tests/CreatesApplication.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests;

use Illuminate\Contracts\Console\Kernel;
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use LaravelZero\Framework\Exceptions\ConsoleException;

it('ensures configuration file is valid', function () {
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/DirtyTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use App\Contracts\PathsRepository;

it('determines dirty files', function () {
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/BinaryOperatorSpacesFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/binary_operator_spaces.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/BlankLineBeforeStatementFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/blank_line_before_statement.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/BracesFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/braces.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/ClassConstructorFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/class_constructor.php'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/extra_whitespaces_in_single_line_anonymous_function.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/JsonFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/file.json'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/LaravelPhpdocAlignmentFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/laravel_phpdoc_alignment.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/LaravelPhpdocOrderFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/laravel_phpdoc_order.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/LaravelPhpdocSeparationFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/laravel_phpdoc_separation.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/OrderedTypesFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/ordered_types.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/ParenthesesFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/parentheses.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/SingleLineEmptyObjectFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/single_line_empty_object.php'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/XmlFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the xml', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/file.xml'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Fixers/YamlFixerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/file.yml'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/FormatTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('outputs checkstyle format', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/with-fixable-issues'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/PresetTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('uses the laravel preset by default', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/without-issues'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/ProgressTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('display progress when fixing issues', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/with-fixable-issues'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/SummaryTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('may fail with style issues', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/with-fixable-issues'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/VerboseTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('displays the code diff', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/with-fixable-issues'),
Expand Down
2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Test Case
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests;

use LaravelZero\Framework\Testing\TestCase as BaseTestCase;
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Repositories/ConfigurationJsonRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use DragonCode\CodeStyler\Helpers\PhpVersion;
use DragonCode\CodeStyler\Repositories\ConfigurationJsonRepository;

Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/ValueObjects/IssueTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use App\ValueObjects\Issue;

it('has a description', function () {
Expand Down

0 comments on commit 784218a

Please sign in to comment.