Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"type": "library",
"require": {
"php": "^8.1",
"friendsofphp/php-cs-fixer": "^3.49",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.20"
"friendsofphp/php-cs-fixer": "^3.58",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.21"
},
"require-dev": {
"jetbrains/phpstorm-attributes": "^1.0",
"phpunit/phpunit": "^10.0",
"symfony/console": "^6.0"
"jetbrains/phpstorm-attributes": "^1.1",
"phpunit/phpunit": "^10.0|^11.2",
"symfony/console": "^6.0|^7.0"
},
"authors": [
{
Expand Down
58 changes: 56 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use JetBrains\PhpStorm\ArrayShape;
use PhpCsFixer\Config as PhpCsFixerConfig;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfig;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use PhpCsFixerCustomFixers\Fixers as PhpCsFixerCustomFixers;

class Config
Expand All @@ -27,6 +29,9 @@ class Config
protected Rules $rules;
protected string $rootPath;
protected bool $withRiskyFixers = true;
protected bool $withCache = true;
protected bool $withParallelRun = true;
protected ?ParallelConfig $customParallelRunConfig = null;
protected bool $ignoreMarkedFiles = false;

public function __construct(
Expand Down Expand Up @@ -57,12 +62,18 @@ public function config(): PhpCsFixerConfig
$finder = Finder::create()->directories()->append($filteredFiles);
$config = new PhpCsFixerConfig("Blumilk codestyle standard");

return $config->setFinder($finder)
->setUsingCache(false)
$config = $config->setFinder($finder)
->setUsingCache($this->withCache)
->registerCustomFixers(new PhpCsFixerCustomFixers())
->registerCustomFixers($this->getCustomFixers())
->setRiskyAllowed($this->withRiskyFixers)
->setRules($rules);

if ($this->withParallelRun) {
$config = $config->setParallelConfig($this->withCustomParallelRunConfig ?? ParallelConfigFactory::detect());
}

return $config;
}

#[ArrayShape(["paths" => "array", "rules" => "array"])]
Expand All @@ -81,13 +92,56 @@ public function purgeMode(bool $purgeDocComments = true): static
return $this;
}

public function withRiskyFixers(): static
{
$this->withRiskyFixers = true;

return $this;
}

public function withoutRiskyFixers(): static
{
$this->withRiskyFixers = false;

return $this;
}

public function withCache(): static
{
$this->withCache = true;

return $this;
}

public function withoutCache(): static
{
$this->withCache = false;

return $this;
}

public function withParallelRun(): static
{
$this->withParallelRun = true;

return $this;
}

public function withoutParallelRun(): static
{
$this->withParallelRun = false;

return $this;
}

public function withCustomParallelRunConfig(ParallelConfig $config): static
{
$this->withParallelRun();
$this->customParallelRunConfig = $config;

return $this;
}

public function ignoreMarkedFiles(): static
{
$this->ignoreMarkedFiles = true;
Expand Down
4 changes: 4 additions & 0 deletions src/Configuration/Defaults/CommonRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PhpCsFixer\Fixer\Basic\NoMultipleStatementsPerLineFixer;
use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer;
use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer;
use PhpCsFixer\Fixer\Casing\ConstantCaseFixer;
use PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer;
use PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer;
use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer;
Expand Down Expand Up @@ -88,6 +89,7 @@
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer;
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitAttributesFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitSetUpTearDownVisibilityFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
Expand Down Expand Up @@ -342,5 +344,7 @@ class CommonRules extends Rules
ClassKeywordFixer::class => true,
NamedArgumentFixer::class => true,
NoBlankLinesAfterPhpdocFixer::class => true,
ConstantCaseFixer::class => true,
PhpUnitAttributesFixer::class => true,
];
}
1 change: 0 additions & 1 deletion tests/codestyle/CodestyleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ protected function tearDown(): void
}

/**
* @dataProvider providePhp80Fixtures
* @throws Exception
*/
protected function testFixture(string $name): void
Expand Down
14 changes: 8 additions & 6 deletions tests/codestyle/CommonRulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@
namespace Blumilk\Codestyle\Tests;

use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhp;

class CommonRulesetTest extends CodestyleTestCase
{
/**
* @dataProvider providePhp80Fixtures
* @requires PHP >= 8.0
* @throws Exception
*/
#[DataProvider("providePhp80Fixtures")]
#[RequiresPhp(">= 8.0")]
public function testPhp80Fixtures(string $name): void
{
$this->testFixture($name);
}

/**
* @dataProvider providePhp81Fixtures
* @requires PHP >= 8.1
* @throws Exception
*/
#[DataProvider("providePhp81Fixtures")]
#[RequiresPhp(">= 8.1")]
public function testPhp81Fixtures(string $name): void
{
$this->testFixture($name);
}

/**
* @dataProvider providePhp82Fixtures
* @requires PHP >= 8.2
* @throws Exception
*/
#[DataProvider("providePhp82Fixtures")]
#[RequiresPhp(">= 8.2")]
public function testPhp82Fixtures(string $name): void
{
$this->testFixture($name);
Expand Down
1 change: 0 additions & 1 deletion tests/codestyle/IgnoreMarkedFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ protected function getConfigPath(): string
}

/**
* @dataProvider providePhp80Fixtures
* @throws Exception
*/
protected function testFixture(string $name): void
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/lowercaseKeywords/actual.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Class LowercaseKeywordsTest Extends ObjectOperatorTest
{
public bool $true = TRUE;

PUBLIC function test(): int
{
Foreach (range(1, 5) as $item) {
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/lowercaseKeywords/expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class LowercaseKeywordsTest extends ObjectOperatorTest
{
public bool $true = true;

public function test(): int
{
foreach (range(1, 5) as $item) {
Expand Down