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

chore: Update the PHP-CS-Fixer config #833

Merged
merged 4 commits into from
Jan 19, 2023
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
132 changes: 29 additions & 103 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,112 +1,38 @@
<?php declare(strict_types=1);

$header = <<<'EOF'
This file is part of the box project.
use Fidry\PhpCsFixerConfig\FidryConfig;
use PhpCsFixer\Finder;

(c) Kevin Herrera <kevin@herrera.io>
Théo Fidry <theo.fidry@gmail.com>
$finder = Finder::create()
->in([
'fixtures',
'bin',
'src',
'tests',
])
->append([
'bin/box',
'bin/generate_default_stub',
]);

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;
$overriddenRules = [
'header_comment' => [
'header' => <<<'EOF'
This file is part of the box project.

$config = (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PHP71Migration:risky' => true,
'@PHP70Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => [
'statements' => [
'continue',
'declare',
'return',
'throw',
'try',
],
],
'blank_line_between_import_groups' => false,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'global_namespace_import' => [
'import_constants' => true,
'import_functions' => true,
'import_classes' => true,
],
'header_comment' => ['header' => $header],
'heredoc_to_nowdoc' => true,
'heredoc_indentation' => true,
'list_syntax' => ['syntax' => 'short'],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
],
'native_function_invocation' => false,
'no_extra_blank_lines' => [
'tokens' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block'
]
],
'no_null_property_initialization' => true,
'echo_tag_syntax' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_unused_imports' => true,
'ordered_imports' => true,
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_types_order' => true,
'php_unit_method_casing' => [
'case' => 'snake_case',
],
'semicolon_after_instruction' => true,
'single_line_throw' => false,
'strict_param' => true,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => [
'arrays',
'arguments',
'parameters',
],
],
'yoda_style' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in('fixtures')
->in('src')
->in('tests')
->append(['bin/box'])
->notName('default_stub.php')
->exclude('check-requirements')
->exclude('fixtures/build/dir012/var')
)
;
(c) Kevin Herrera <kevin@herrera.io>
Théo Fidry <theo.fidry@gmail.com>

$config->setCacheFile(__DIR__.'/dist/.php-cs-fixer.cache');
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF,
'location' => 'after_declare_strict',
],
];

(new PhpCsFixer\FixerFactory())
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new PhpCsFixer\RuleSet\RuleSet($config->getRules()))
;
$config = new FidryConfig('', 81_000);
$config->addRules($overriddenRules);
$config->setCacheFile(__DIR__.'/dist/.php-cs-fixer.cache');
$config->setFinder($finder);

return $config;
6 changes: 3 additions & 3 deletions bin/box
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ namespace KevinGH\Box;

use Fidry\Console\Application\ApplicationRunner;
use Fidry\Console\Input\IO;
use function file_exists;
use function in_array;
use KevinGH\Box\Console\Application;
use KevinGH\Box\Console\OutputFormatterConfigurator;
use RuntimeException;
use function file_exists;
use function in_array;
use const PHP_EOL;
use const PHP_SAPI;
use RuntimeException;

// See https://github.com/easysoft/phpmicro for the micro SAPI.
if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed', 'micro'], true)) {
Expand Down
4 changes: 2 additions & 2 deletions bin/generate_default_stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
Expand All @@ -11,8 +13,6 @@
* with this source code in the file LICENSE.
*/

declare(strict_types=1);

$phar = new Phar('tmp.phar');
$phar->setDefaultStub();

Expand Down
3 changes: 0 additions & 3 deletions fixtures/Compactor/DummyCompactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

class DummyCompactor implements Compactor
{
/**
* {@inheritdoc}
*/
public function compact(string $file, string $contents): string
{
return $contents;
Expand Down
6 changes: 0 additions & 6 deletions fixtures/Compactor/DummyFileExtensionCompactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@

class DummyFileExtensionCompactor extends FileExtensionCompactor
{
/**
* {@inheritdoc}
*/
protected function compactContent(string $contents): string
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
}

/**
* {@inheritdoc}
*/
protected function supports(string $file): bool
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
Expand Down
3 changes: 0 additions & 3 deletions fixtures/Compactor/FakeCompactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

class FakeCompactor implements Compactor
{
/**
* {@inheritdoc}
*/
public function compact(string $file, string $contents): string
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
Expand Down
5 changes: 1 addition & 4 deletions fixtures/PhpScoper/CallRecorderScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@

namespace KevinGH\Box\PhpScoper;

use function func_get_args;
use Humbug\PhpScoper\Scoper\Scoper as PhpScoperScoper;
use function func_get_args;

final class CallRecorderScoper implements PhpScoperScoper
{
private $calls = [];

/**
* {@inheritdoc}
*/
public function scope(string $filePath, string $contents): string
{
$this->calls[] = func_get_args();
Expand Down
3 changes: 0 additions & 3 deletions fixtures/PhpScoper/FakePhpScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

final class FakePhpScoper implements PhpScoperScoper
{
/**
* {@inheritdoc}
*/
public function scope(string $filePath, string $contents): string
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
Expand Down
3 changes: 0 additions & 3 deletions fixtures/PhpScoper/FakeScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

final class FakeScoper implements Scoper
{
/**
* {@inheritdoc}
*/
public function scope(string $filePath, string $contents): string
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
Expand Down
9 changes: 0 additions & 9 deletions fixtures/PhpScoper/UnserializableScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,16 @@

final class UnserializableScoper implements PhpScoperScoper, Serializable
{
/**
* {@inheritdoc}
*/
public function scope(string $filePath, string $contents): string
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
}

/**
* {@inheritdoc}
*/
public function serialize(): string
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
}

/**
* {@inheritdoc}
*/
public function unserialize($serialized): void
{
throw UnsupportedMethodCall::forMethod(__CLASS__, __METHOD__);
Expand Down
3 changes: 0 additions & 3 deletions fixtures/Verifier/DummyPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

class DummyPublicKey extends PublicKey
{
/**
* {@inheritdoc}
*/
public function verify(string $signature): bool
{
return true;
Expand Down
2 changes: 1 addition & 1 deletion fixtures/build/dir012/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

if ($_SERVER['APP_DEBUG']) {
umask(0000);
umask(0);

Debug::enable();
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/build/dir012/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

namespace App;

use function dirname;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use function dirname;

class Kernel extends BaseKernel
{
Expand Down
3 changes: 2 additions & 1 deletion requirement-checker/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
$config = new FidryConfig('', 74_000);
$config->addRules($overriddenRules);
$config->setCacheFile(__DIR__.'/dist/.php-cs-fixer.cache');
$config->setFinder($finder);

return $config->setFinder($finder);
return $config;
4 changes: 2 additions & 2 deletions src/Amp/FailureCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
namespace KevinGH\Box\Amp;

use Amp\MultiReasonException;
use function array_map;
use function array_unique;
use KevinGH\Box\NotInstantiable;
use Throwable;
use function array_map;
use function array_unique;

final class FailureCollector
{
Expand Down
6 changes: 3 additions & 3 deletions src/Annotation/CompactedFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

namespace KevinGH\Box\Annotation;

use function array_map;
use function explode;
use function implode;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
use function array_map;
use function explode;
use function implode;

final class CompactedFormatter implements Formatter
{
Expand Down
11 changes: 5 additions & 6 deletions src/Annotation/DocblockAnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

namespace KevinGH\Box\Annotation;

use function array_filter;
use function array_key_exists;
use function array_map;
use function array_values;
use InvalidArgumentException;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use function array_filter;
use function array_key_exists;
use function array_map;
use function array_values;
use function Safe\array_flip;
use function strtolower;

/**
* @private
Expand Down Expand Up @@ -86,7 +85,7 @@ private static function extractTags(DocBlock $docBlock, array $ignoredAnnotation
array_filter(
$docBlock->getTags(),
static fn (Tag $tag) => !array_key_exists(
strtolower($tag->getName()),
mb_strtolower($tag->getName()),
$ignoredAnnotations,
),
),
Expand Down
Loading