Skip to content

Commit

Permalink
PHPStan, Rector and ECS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Nov 16, 2021
1 parent 77ee72b commit 3e6c522
Show file tree
Hide file tree
Showing 89 changed files with 1,055 additions and 1,804 deletions.
69 changes: 0 additions & 69 deletions .php-cs-fixer.dist.php

This file was deleted.

9 changes: 0 additions & 9 deletions .scrutinizer.yml

This file was deleted.

57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@
"ext-mbstring": "*"
},
"require-dev": {
"ekino/phpstan-banned-code": "^0.5.0",
"friendsofphp/php-cs-fixer": "^2.0|^3.0",
"ext-json": "*",
"ekino/phpstan-banned-code": "^1.0",
"infection/infection": "^0.18|^0.25",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-beberlei-assert": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.11.53",
"rector/rector": "^0.12",
"roave/security-advisories": "dev-latest",
"symfony/var-dumper": "^5.3"
"symfony/var-dumper": "^5.3",
"symplify/easy-coding-standard": "^9.4"
},
"config": {
"sort-packages": true
Expand Down
120 changes: 120 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

declare(strict_types=1);

use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff;
use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer;
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\ClassNotation\ProtectedToPrivateFixer;
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer;
use PhpCsFixer\Fixer\ControlStructure\NoSuperfluousElseifFixer;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer;
use PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer;
use PhpCsFixer\Fixer\PhpTag\LinebreakAfterOpeningTagFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestClassRequiresCoversFixer;
use PhpCsFixer\Fixer\ReturnNotation\SimplifiedNullReturnFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

$header = '';

return static function (ContainerConfigurator $containerConfigurator) use ($header): void {
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::PHP_CS_FIXER);
$containerConfigurator->import(SetList::PHP_CS_FIXER_RISKY);
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::SYMFONY);
$containerConfigurator->import(SetList::DOCTRINE_ANNOTATIONS);
$containerConfigurator->import(SetList::SPACES);
$containerConfigurator->import(SetList::PHPUNIT);
$containerConfigurator->import(SetList::SYMPLIFY);
$containerConfigurator->import(SetList::ARRAY);
$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::COMMENTS);
$containerConfigurator->import(SetList::CONTROL_STRUCTURES);
$containerConfigurator->import(SetList::DOCBLOCK);
$containerConfigurator->import(SetList::NAMESPACES);
$containerConfigurator->import(SetList::STRICT);

$services = $containerConfigurator->services();
$services->set(StrictParamFixer::class);
$services->set(StrictComparisonFixer::class);
$services->set(ArraySyntaxFixer::class)
->call('configure', [[
'syntax' => 'short',
]])
;
$services->set(ArrayIndentationFixer::class);
$services->set(OrderedImportsFixer::class);
$services->set(ProtectedToPrivateFixer::class);
$services->set(DeclareStrictTypesFixer::class);
$services->set(NativeConstantInvocationFixer::class);
$services->set(NativeFunctionInvocationFixer::class)
->call('configure', [[
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
]])
;
$services->set(MbStrFunctionsFixer::class);
$services->set(LinebreakAfterOpeningTagFixer::class);
$services->set(CombineConsecutiveIssetsFixer::class);
$services->set(CombineConsecutiveUnsetsFixer::class);
$services->set(CompactNullableTypehintFixer::class);
$services->set(NoSuperfluousElseifFixer::class);
$services->set(NoSuperfluousPhpdocTagsFixer::class);
$services->set(PhpdocTrimConsecutiveBlankLineSeparationFixer::class);
$services->set(PhpdocOrderFixer::class);
$services->set(SimplifiedNullReturnFixer::class);
$services->set(HeaderCommentFixer::class)
->call('configure', [[
'header' => $header,
]])
;
$services->set(AlignMultilineCommentFixer::class)
->call('configure', [[
'comment_type' => 'all_multiline',
]])
;
$services->set(PhpUnitTestAnnotationFixer::class)
->call('configure', [[
'style' => 'annotation',
]])
;
$services->set(PhpUnitTestCaseStaticMethodCallsFixer::class);
$services->set(GlobalNamespaceImportFixer::class)
->call('configure', [[
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
]])
;

// The absence of @cover in tests is OK
$services->remove(PhpUnitTestClassRequiresCoversFixer::class);

// The assignment in if of while statements are OK
$services->remove(AssignmentInConditionSniff::class);

$parameters = $containerConfigurator->parameters();
$parameters
->set(Option::PATHS, [__DIR__])
->set(Option::SKIP, [__DIR__ . '/.github', __DIR__ . '/build', __DIR__ . '/vendor'])
;
};
32 changes: 32 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,35 @@ parameters:
message: '#Method CBOR\\OtherObject\\NullObject\:\:normalize\(\) should return mixed but return statement is missing\.#'
count: 1
path: src/OtherObject/NullObject.php
-
message: '#Class CBOR\\TextStringWithChunkObject extends \@final class CBOR\\IndefiniteLengthTextStringObject\.#'
count: 1
path: src/TextStringWithChunkObject.php
-
message: '#Class CBOR\\Tag\\TagObjectManager extends \@final class CBOR\\Tag\\TagManager\.#'
count: 1
path: src/Tag/TagObjectManager.php
-
message: '#Class CBOR\\Tag\\PositiveBigIntegerTag extends \@final class CBOR\\Tag\\UnsignedBigIntegerTag\.#'
count: 1
path: src/Tag/PositiveBigIntegerTag.php
-
message: '#Class CBOR\\Tag\\EpochTag extends \@final class CBOR\\Tag\\DatetimeTag\.#'
count: 1
path: src/Tag/EpochTag.php
-
message: '#Class CBOR\\SignedIntegerObject extends \@final class CBOR\\NegativeIntegerObject\.#'
count: 1
path: src/SignedIntegerObject.php
-
message: '#Class CBOR\\InfiniteMapObject extends \@final class CBOR\\IndefiniteLengthMapObject\.#'
count: 1
path: src/InfiniteMapObject.php
-
message: '#Class CBOR\\InfiniteListObject extends \@final class CBOR\\IndefiniteLengthListObject\.#'
count: 1
path: src/InfiniteListObject.php
-
message: '#Class CBOR\\ByteStringWithChunkObject extends \@final class CBOR\\IndefiniteLengthByteStringObject\.#'
count: 1
path: src/ByteStringWithChunkObject.php
6 changes: 4 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SymfonySetList::SYMFONY_52);
$containerConfigurator->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
$containerConfigurator->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$containerConfigurator->import(SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION);
$containerConfigurator->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__.'/src', __DIR__.'/tests']);
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
Expand Down
10 changes: 1 addition & 9 deletions src/AbstractCBORObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

declare(strict_types=1);

/*
* The MIT License (MIT)
*
* Copyright (c) 2018-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR;

use function chr;
Expand All @@ -21,6 +12,7 @@ abstract class AbstractCBORObject implements CBORObject
* @var int
*/
protected $additionalInformation;

/**
* @var int
*/
Expand Down
Loading

0 comments on commit 3e6c522

Please sign in to comment.