Skip to content

Commit

Permalink
refactor: apply new coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Aug 2, 2024
1 parent a0c9d6d commit 59acbcf
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 32 deletions.
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
8 changes: 5 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +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 @@ -34,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
2 changes: 1 addition & 1 deletion 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 Down
5 changes: 4 additions & 1 deletion 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 Down Expand Up @@ -80,7 +83,7 @@ $fixers = array_map(static function (AbstractFixer $fixer) {
];
}, $samples),
];
}, iterator_to_array(new PedroTroller\CS\Fixer\Fixers()));
}, [...(new Fixers())]);

$loader = new FilesystemLoader([__DIR__]);
$twig = new Environment($loader);
Expand Down
23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"description": "PHP-CS-FIXER : my custom fixers",
"license": "MIT",
"require": {
"php": "^8.0"
"php": "^8.1",
"friendsofphp/php-cs-fixer": "^3.28"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.28",
"phpspec/phpspec": "^7.0",
"sebastian/diff": "^4.0",
"twig/twig": "^3.3",
"webmozart/assert": "^1.10"
},
"conflict": {
"friendsofphp/php-cs-fixer": ">3.59.2"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"PedroTroller\\CS\\Fixer\\": "src/PedroTroller/CS/Fixer"
Expand All @@ -31,19 +36,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"
]
}
}
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/PedroTroller/CS/Fixer/RuleSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function create(array $rules = []): self
);
}

public function per(int|float $version = null, bool $risky = false): self
public function per(null|float|int $version = null, bool $risky = false): self
{
$candidates = null !== $version
? ['@PER-CS'.number_format($version, 1, '.', '')]
Expand Down Expand Up @@ -198,7 +198,7 @@ public function pedrotroller(bool $risky = false): self
));
}

public function enable(string $name, array $config = null): self
public function enable(string $name, ?array $config = null): self
{
return self::create(array_merge(
$this->rules,
Expand Down
2 changes: 1 addition & 1 deletion tests/TokensAnalyzerIntegration/MethodArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function assertions(TokensAnalyzer $analyzer, Tokens $tokens): void
$arguments,
[
($theFunction + 5) => [
'type' => 'Domain\\Model\\User',
'type' => 'Domain\Model\User',
'name' => '$user',
'nullable' => false,
'asDefault' => false,
Expand Down

0 comments on commit 59acbcf

Please sign in to comment.