Skip to content

Commit

Permalink
Merge pull request #222 from TheDragonCode/4.x
Browse files Browse the repository at this point in the history
Fixed file processing error for PHP 8.3
  • Loading branch information
andrey-helldar authored Mar 27, 2024
2 parents 130fb1a + 42fe27f commit 4586434
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 70 deletions.
93 changes: 46 additions & 47 deletions app/Commands/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,57 @@ public function handle(FixCode $fixCode, ElaborateSummary $summary): int

protected function configure(): void
{
$this
->setDefinition(
[
new InputArgument(
'path',
InputArgument::IS_ARRAY,
'The path to fix',
[(string) getcwd()]
),
$this->setDefinition(
[
new InputArgument(
'path',
InputArgument::IS_ARRAY,
'The path to fix',
[(string) getcwd()]
),

new InputOption(
'config',
'',
InputOption::VALUE_REQUIRED,
'The configuration that should be used'
),
new InputOption(
'config',
'',
InputOption::VALUE_REQUIRED,
'The configuration that should be used'
),

new InputOption(
'test',
'',
InputOption::VALUE_NONE,
'Test for code style errors without fixing them'
),
new InputOption(
'test',
'',
InputOption::VALUE_NONE,
'Test for code style errors without fixing them'
),

new InputOption(
'risky',
'',
InputOption::VALUE_NONE,
'Allows the application of risky rules'
),
new InputOption(
'risky',
'',
InputOption::VALUE_NONE,
'Allows the application of risky rules'
),

new InputOption(
'dirty',
'',
InputOption::VALUE_NONE,
'Only fix files that have uncommitted changes'
),
new InputOption(
'dirty',
'',
InputOption::VALUE_NONE,
'Only fix files that have uncommitted changes'
),

new InputOption(
'bail',
'',
InputOption::VALUE_NONE,
'Test for code style errors without fixing them and stop on first error'
),
new InputOption(
'bail',
'',
InputOption::VALUE_NONE,
'Test for code style errors without fixing them and stop on first error'
),

new InputOption(
'format',
'',
InputOption::VALUE_REQUIRED,
'The output format that should be used'
),
]
);
new InputOption(
'format',
'',
InputOption::VALUE_REQUIRED,
'The output format that should be used'
),
]
);
}
}
19 changes: 19 additions & 0 deletions app/Enums/PhpVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace DragonCode\CodeStyler\Enums;

use ArchTech\Enums\Values;

enum PhpVersion: string
{
use Values;

case v81 = '8.1';
case v81risky = '8.1-risky';
case v82 = '8.2';
case v82risky = '8.2-risky';
case v83 = '8.3';
case v83risky = '8.3-risky';
}
15 changes: 7 additions & 8 deletions app/Factories/ConfigurationResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Project;
use ArrayIterator;
use DragonCode\CodeStyler\Enums\PhpVersion;
use DragonCode\CodeStyler\Repositories\ConfigurationJsonRepository;
use PhpCsFixer\Config;
use PhpCsFixer\Console\ConfigurationResolver;
Expand All @@ -29,21 +30,14 @@

class ConfigurationResolverFactory
{
public static array $presets = [
'8.1',
'8.1-risky',
'8.2',
'8.2-risky',
];

public static function fromIO(InputInterface $input, OutputInterface $output): array
{
$path = static::paths($input);
$configuration = static::configuration();

$preset = $configuration->preset();

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

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

Expand Down Expand Up @@ -113,4 +107,9 @@ protected static function allowRisky(InputInterface $input): string
{
return $input->getOption('risky') ? 'yes' : 'no';
}

protected static function presets(): array
{
return PhpVersion::values();
}
}
1 change: 1 addition & 0 deletions app/Output/SummaryOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Output\SummaryOutput as BaseOutput;

/** @see \DragonCode\CodeStyler\Enums\PhpVersion */
class SummaryOutput extends BaseOutput
{
protected $presets = [
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"ext-xml": "*"
},
"require-dev": {
"archtechx/enums": "^1.0",
"dragon-code/pretty-array": "^4.1",
"dragon-code/support": "^6.12.0",
"friendsofphp/php-cs-fixer": "^3.49.0",
Expand Down
48 changes: 47 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 20 additions & 10 deletions tests/Feature/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
->toContain('<?xml version="1.0" encoding="UTF-8"?>')
->toContain('<checkstyle>')
->toContain('</checkstyle>')
->not->toContain(sprintf('⨯ %s',
->not->toContain(sprintf(
'⨯ %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-fixable-issues',
'file.php',
])));
])
));
});

it('outputs json format', function () {
Expand All @@ -30,13 +32,15 @@
->and($output)
->toBeJson()
->toContain('appliedFixers')
->not->toContain(sprintf('⨯ %s',
->not->toContain(sprintf(
'⨯ %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-fixable-issues',
'file.php',
])));
])
));
});

it('outputs xml format', function () {
Expand All @@ -48,13 +52,15 @@
expect($statusCode)->toBe(1)
->and($output)
->toContain('<?xml version="1.0" encoding="UTF-8"?>')
->not->toContain(sprintf('⨯ %s',
->not->toContain(sprintf(
'⨯ %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-fixable-issues',
'file.php',
])));
])
));
});

it('outputs junit format', function () {
Expand All @@ -67,13 +73,15 @@
->and($output)
->toContain('<?xml version="1.0" encoding="UTF-8"?>')
->toContain('CDATA')
->not->toContain(sprintf('⨯ %s',
->not->toContain(sprintf(
'⨯ %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-fixable-issues',
'file.php',
])));
])
));
});

it('outputs gitlab format', function () {
Expand All @@ -86,11 +94,13 @@
->and($output)
->toBeJson()
->toContain('fingerprint')
->not->toContain(sprintf('⨯ %s',
->not->toContain(sprintf(
'⨯ %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-fixable-issues',
'file.php',
])));
])
));
});
12 changes: 8 additions & 4 deletions tests/Feature/SummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
->and($output)
->toContain('FAIL')
->toContain('1 file, 1 style issue')
->toContain(sprintf('⨯ %s',
->toContain(sprintf(
'⨯ %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-fixable-issues',
'file.php',
])))->toContain('new_with_parentheses');
])
))->toContain('new_with_parentheses');
});

it('may fail with errors', function () {
Expand All @@ -27,13 +29,15 @@
->and($output)
->toContain('FAIL')
->toContain('1 file, 1 error')
->toContain(sprintf('! %s',
->toContain(sprintf(
'! %s',
implode(DIRECTORY_SEPARATOR, [
'tests',
'Fixtures',
'with-non-fixable-issues',
'file.php',
])))->toContain('Parse error: syntax error');
])
))->toContain('Parse error: syntax error');
});

it('may pass', function () {
Expand Down

0 comments on commit 4586434

Please sign in to comment.