Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release #212

Closed
wants to merge 7 commits into from
Closed
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
18 changes: 14 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,29 @@ workflows:
- documentation:
matrix:
parameters:
php-version: ["8.2"]
php-version:
- "8.3"
- tests:
matrix:
parameters:
php-version: ["8.0", "8.1", "8.2"]
php-version:
- "8.1"
- "8.2"
- "8.3"
- tests-with-future-mode:
matrix:
parameters:
php-version: ["8.0", "8.1", "8.2"]
php-version:
- "8.1"
- "8.2"
- "8.3"
- tests-with-lowest-dependencies:
matrix:
parameters:
php-version: ["8.0", "8.1", "8.2"]
php-version:
- "8.1"
- "8.2"
- "8.3"
- release-test
- release:
requires:
Expand Down
9 changes: 6 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

use PedroTroller\CS\Fixer\Fixers;
use PedroTroller\CS\Fixer\RuleSetFactory;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

return (new PhpCsFixer\Config())
return (new Config())
->setRiskyAllowed(true)
->setRules(
RuleSetFactory::create()
->per(2, true)
->phpCsFixer(true)
->php(8.0, true)
->php(8.1, true)
->pedrotroller(true)
->enable('align_multiline_comment')
->enable('array_indentation')
Expand All @@ -33,7 +36,7 @@
->setUsingCache(false)
->registerCustomFixers(new Fixers())
->setFinder(
PhpCsFixer\Finder::create()
Finder::create()
->in(__DIR__)
->append([__FILE__, __DIR__.'/bin/doc'])
)
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ Prohibited functions MUST BE commented on as prohibited

### Available options

- `functions` (*optional*): The function names to be marked how prohibited
- default: `var_dump`, `dump`, `die`

- `comment` (*optional*): The prohibition message to put in the comment
- default: `@TODO remove this line`

- `functions` (*optional*): The function names to be marked how prohibited
- default: `var_dump`, `dump`, `die`

### Configuration examples

```php
Expand Down Expand Up @@ -511,18 +511,18 @@ If the declaration of a method is too long, the arguments of this method MUST BE

### Available options

- `max-args` (*optional*): The maximum number of arguments allowed with splitting the arguments into several lines (use `false` to disable this feature)
- default: `3`

- `max-length` (*optional*): The maximum number of characters allowed with splitting the arguments into several lines
- default: `120`

- `automatic-argument-merge` (*optional*): If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline
- default: `true`

- `inline-attributes` (*optional*): In the case of a split, the declaration of the attributes of the arguments of the method will be on the same line as the arguments themselves
- default: `false`

- `max-args` (*optional*): The maximum number of arguments allowed with splitting the arguments into several lines (use `false` to disable this feature)
- default: `3`

- `max-length` (*optional*): The maximum number of characters allowed with splitting the arguments into several lines
- default: `120`

### Configuration examples

```php
Expand Down
4 changes: 2 additions & 2 deletions bin/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class Utils
{
public static function arrayToString(array $array = null)
public static function arrayToString(?array $array = null)
{
if (null === $array) {
return;
Expand All @@ -15,7 +15,7 @@ public static function arrayToString(array $array = null)
if (array_values($array) === $array) {
$string .= implode(', ', array_map([self::class, 'valueToString'], $array));
} else {
$string .= implode(', ', array_map(fn ($value, $key) => '\''.$key.'\' => '.self::valueToString($value), $array, array_keys($array)));
$string .= implode(', ', array_map(static fn ($value, $key) => '\''.$key.'\' => '.self::valueToString($value), $array, array_keys($array)));
}

$string .= ' ]';
Expand Down
17 changes: 10 additions & 7 deletions bin/doc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

use PedroTroller\CS\Fixer\AbstractFixer;
use PedroTroller\CS\Fixer\Fixers;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
use PhpCsFixer\FixerDefinition\CodeSample;
Expand All @@ -14,7 +17,7 @@ include sprintf('%s/../vendor/autoload.php', __DIR__);

include 'Utils.php';

$fixers = array_map(function (AbstractFixer $fixer) {
$fixers = array_map(static function (AbstractFixer $fixer) {
$samples = $fixer->getDefinition()->getCodeSamples();

return [
Expand All @@ -25,7 +28,7 @@ $fixers = array_map(function (AbstractFixer $fixer) {
'deprecated' => $fixer->isDeprecated(),
'replacement' => $fixer->getDeprecationReplacement(),
'options' => array_map(
function (FixerOptionInterface $option) {
static function (FixerOptionInterface $option) {
return [
'name' => $option->getName(),
'description' => $option->getDescription(),
Expand All @@ -39,7 +42,7 @@ $fixers = array_map(function (AbstractFixer $fixer) {
? $fixer->getConfigurationDefinition()->getOptions()
: []
),
'samples' => array_map(function (CodeSample $sample) use ($fixer) {
'samples' => array_map(static function (CodeSample $sample) use ($fixer) {
if ($fixer instanceof ConfigurableFixerInterface) {
$fixer->configure($sample->getConfiguration());
}
Expand All @@ -57,13 +60,13 @@ $fixers = array_map(function (AbstractFixer $fixer) {
}

while (strlen($line) < 80 + 1) {
$line = $line.' ';
$line .= ' ';
}

if (0 === $num) {
$line = $line.'// 80 chars';
$line .= '// 80 chars';
} else {
$line = $line.'//';
$line .= '//';
}

$diff[$num] = $line;
Expand All @@ -80,7 +83,7 @@ $fixers = array_map(function (AbstractFixer $fixer) {
];
}, $samples),
];
}, iterator_to_array(new PedroTroller\CS\Fixer\Fixers()));
}, [...(new Fixers())]);

$loader = new FilesystemLoader([__DIR__]);
$twig = new Environment($loader);
Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
"description": "PHP-CS-FIXER : my custom fixers",
"license": "MIT",
"require": {
"php": "^8.0"
"php": "^8.1",
"friendsofphp/php-cs-fixer": ">=3.59.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.17",
"friendsofphp/php-cs-fixer": "^3.60",
"phpspec/phpspec": "^7.0",
"sebastian/diff": "^4.0",
"twig/twig": "^3.3",
"webmozart/assert": "^1.10"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"PedroTroller\\CS\\Fixer\\": "src/PedroTroller/CS/Fixer"
Expand All @@ -31,19 +34,17 @@
"dev-master": "3.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"tests": [
"tests\\Runner::run",
"tests\\Orchestra::run",
"phpspec run -fpretty"
"lint": [
"@php-cs-fixer"
],
"php-cs-fixer": [
"php-cs-fixer fix --dry-run -vvv --diff"
],
"lint": [
"@php-cs-fixer"
"tests": [
"tests\\Runner::run",
"tests\\Orchestra::run",
"phpspec run -fpretty"
]
}
}
6 changes: 5 additions & 1 deletion doc/rule-set-factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ return PhpCsFixer\Config::create()
->setRules(RuleSetFactory::create()
->symfony() // Activate the @Symfony ruleset
->phpCsFixer() // Activate the @PhpCsFixer ruleset
->php(5.6, true) // Activate php 5.6 risky rules
->php(8.2, true) // Activate php 8.2 risky rules
->pedrotroller(true) // Activate my own ruleset (with risky rules)
->enable('ordered_imports') // Add an other rule
->disable('yoda_style') // Disable a rule
Expand All @@ -26,6 +26,10 @@ return PhpCsFixer\Config::create()

## Methods

### `->per([int|float $version = null, [bool $risky = false]])`

Activate the `@PER` (`@PER-CS1.0`, `@PER-CS1.0:risky`, `@PER-CS2.0`, `@PER-CS2.0:risky`, ...) rule.

### `->psr0()`

Activate the `@psr0` rule.
Expand Down
48 changes: 35 additions & 13 deletions spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,46 @@

final class RuleSetFactorySpec extends ObjectBehavior
{
function let()
{
$this->beConstructedThrough('create');
}

function it_is_initializable()
{
$this->shouldHaveType(RuleSetFactory::class);
}

function it_adds_a_per_set()
{
$this->per()->getRules()->shouldReturn(['@PER' => true]);
}

function it_adds_a_per_risky_set()
{
$this->per(risky: true)->getRules()->shouldReturn(['@PER:risky' => true]);
}

function it_adds_a_per1_0_set()
{
$this->per(1)->getRules()->shouldReturn(['@PER-CS1.0' => true]);
}

function it_adds_a_per1_0_risky_set()
{
$this->per(1, true)->getRules()->shouldReturn(['@PER-CS1.0:risky' => true]);
}

function it_adds_a_per2_0_set()
{
$this->per(2)->getRules()->shouldReturn(['@PER-CS2.0' => true]);
}

function it_adds_a_per2_0_risky_set()
{
$this->per(2, true)->getRules()->shouldReturn(['@PER-CS2.0:risky' => true]);
}

function it_adds_a_psr0_set()
{
$this->psr0()->getRules()->shouldReturn(['@psr0' => true]);
Expand Down Expand Up @@ -144,15 +179,6 @@ function it_adds_a_php_version_support()
]);
}

function it_can_also_parse_versions_as_string()
{
$this->php('5.6.2')->getRules()->shouldReturn([
'@PHP54Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'list_syntax' => ['syntax' => 'long'],
]);
}

function it_adds_a_phpunit_version_support()
{
$this->phpUnit(2.0, false)->getRules()->shouldReturn([]);
Expand Down Expand Up @@ -310,8 +336,6 @@ function it_adds_my_own_fixer_set()
$rules[$fixer->getName()] = true;
}

ksort($rules);

$this->pedrotroller(true)->getRules()->shouldReturn($rules);
}

Expand All @@ -327,8 +351,6 @@ function it_adds_my_own_fixer_set_except_privates()
$rules[$fixer->getName()] = true;
}

ksort($rules);

$this->pedrotroller(false)->getRules()->shouldReturn($rules);
}

Expand Down
4 changes: 2 additions & 2 deletions src/PedroTroller/CS/Fixer/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function isCandidate(Tokens $tokens): bool

public function getName(): string
{
return sprintf('PedroTroller/%s', parent::getName());
return \sprintf('PedroTroller/%s', parent::getName());
}

/**
Expand All @@ -45,7 +45,7 @@ public function getDefinition(): FixerDefinitionInterface
return new FixerDefinition(
$this->getDocumentation(),
array_map(
fn (array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation),
fn (?array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation),
$this->getSampleConfigurations()
)
);
Expand Down
5 changes: 4 additions & 1 deletion src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
use PedroTroller\CS\Fixer\Priority;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\ConfigurableFixerTrait;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
use PhpCsFixer\Tokenizer\Tokens;

final class OrderBehatStepsFixer extends AbstractOrderedClassElementsFixer implements ConfigurableFixerInterface
{
use ConfigurableFixerTrait;

public const ANNOTATION_PRIORITIES = [
'@BeforeSuite',
'@AfterSuite',
Expand Down Expand Up @@ -126,7 +129,7 @@ public function getDocumentation(): string
return 'Step definition methods in Behat contexts MUST BE ordered by annotation and method name.';
}

public function getConfigurationDefinition(): FixerConfigurationResolverInterface
public function createConfigurationDefinition(): FixerConfigurationResolverInterface
{
return new FixerConfigurationResolver([
(new FixerOptionBuilder('instanceof', 'Parent class or interface of your behat context classes.'))
Expand Down
Loading