improve coding standard, add DeprectionInterface

This commit is contained in:
TomasVotruba 2017-08-06 19:37:55 +02:00
parent 14fe13817a
commit 63bbfb3efc
7 changed files with 113 additions and 10 deletions

View File

@ -4,3 +4,65 @@ includes:
- vendor/symplify/easy-coding-standard/config/php71-checkers.neon
checkers:
# Slevomat
- SlevomatCodingStandard\Sniffs\ControlStructures\DisallowEqualOperatorsSniff
- SlevomatCodingStandard\Sniffs\ControlStructures\YodaComparisonSniff
- SlevomatCodingStandard\Sniffs\Exceptions\DeadCatchSniff
- SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff
- SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff
- SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff
# Files
PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff:
absoluteLineLimit: 120
# PSR-4
- PhpCsFixer\Fixer\Basic\Psr4Fixer
# Code Analysis
- PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff:
absoluteComplexity: 10
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff:
absoluteNestingLevel: 5
# Naming Conventions
- PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff
# PHP
- PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\NonExecutableCodeSniff
# WhiteSpace
- PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff
PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff:
ignoreBlankLines: false
# Namespaces
- PhpCsFixer\Fixer\Import\OrderedImportsFixer
PhpCsFixer\Fixer\Operator\ConcatSpaceFixer:
spacing: one
- PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
- PhpCsFixer\Fixer\LanguageConstruct\DirConstantFixer
- PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer
- PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer
- PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer
- PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer
- PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer
- PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer
- PhpCsFixer\Fixer\Strict\StrictComparisonFixer
PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer:
annotations:
- author
- throws
- expectedException
# PHPUnit
- PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer
# new since PhpCsFixer 2.2-2.4
- PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer
- PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer
- PhpCsFixer\Fixer\Basic\NonPrintableCharacterFixer
- PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer
- PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer

View File

@ -30,8 +30,12 @@ final class FileProcessor
*/
private $lexer;
public function __construct(Parser $parser, FormatPerservingPrinter $codeStyledPrinter, Lexer $lexer, NodeTraverser $nodeTraverser)
{
public function __construct(
Parser $parser,
FormatPerservingPrinter $codeStyledPrinter,
Lexer $lexer,
NodeTraverser $nodeTraverser
) {
$this->parser = $parser;
$this->codeStyledPrinter = $codeStyledPrinter;
$this->nodeTraverser = $nodeTraverser;

View File

@ -17,6 +17,11 @@ final class ReconstructCommand extends Command
*/
private const NAME = 'reconstruct';
/**
* @var string
*/
private const ARGUMENT_SOURCE_NAME = 'source';
/**
* @var FileProcessor
*/
@ -29,11 +34,6 @@ final class ReconstructCommand extends Command
parent::__construct();
}
/**
* @var string
*/
private const ARGUMENT_SOURCE_NAME = 'source';
protected function configure(): void
{
$this->setName(self::NAME);

View File

@ -0,0 +1,21 @@
<?php declare(strict_types=1);
namespace Rector\Contract\Deprecation;
use Rector\Deprecation\SetNames;
interface DeprecationInterface
{
/**
* A project that is related to this.
* E.g "Nette", "Symfony"
* Use constants from @see SetNames, if possible.
*/
public function getSetName(): string;
/**
* Version this deprecations is active since.
* E.g. 2.3
*/
public function sinceVersion(): float;
}

View File

@ -0,0 +1,16 @@
<?php declare(strict_types=1);
namespace Rector\Deprecation;
final class SetNames
{
/**
* @var string
*/
public const NETTE = 'Nette';
/**
* @var string
*/
public const SYMFONY = 'Symfony';
}

View File

@ -9,9 +9,9 @@ use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\NodeVisitorAbstract;
use Rector\Builder\Class_\ClassPropertyCollector;
use Rector\Builder\Kernel\ServiceFromKernelResolver;
use Rector\Builder\Naming\NameResolver;
use Rector\Builder\Class_\ClassPropertyCollector;
use Rector\Tests\NodeVisitor\DependencyInjection\NamedServicesToConstructorReconstructor\Source\LocalKernel;
/**
@ -55,7 +55,7 @@ final class GetterToPropertyNodeVisitor extends NodeVisitorAbstract
/**
* @param Node[] $nodes
* @return array|null
* @return null|array
*/
public function beforeTraverse(array $nodes): ?array
{

View File

@ -8,7 +8,7 @@ final class ReplaceOldConstantNodeVisitor extends AbstraceReplaceDeprecatedConst
{
public function getClassName(): string
{
return'ClassWithConstants';
return 'ClassWithConstants';
}
public function getOldConstantName(): string