Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.4
coverage: none

# composer install cache - https://github.com/ramsey/composer-install
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"description": "Set of Symplify rules for PHP_CodeSniffer and PHP CS Fixer.",
"license": "MIT",
"require": {
"php": ">=8.2",
"nette/utils": "^4.0",
"friendsofphp/php-cs-fixer": "^3.89"
"php": ">=8.4",
"nette/utils": "^4.1",
"friendsofphp/php-cs-fixer": "^3.95.4"
},
"require-dev": {
"symplify/easy-coding-standard": "^12.6",
"symplify/easy-coding-standard": "^13.1",
"squizlabs/php_codesniffer": "^4.0",
"phpunit/phpunit": "^11.5|^12.0",
"phpunit/phpunit": "^12.5",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"rector/rector": "^2.2",
"phpstan/phpstan": "^2.2",
"rector/rector": "^2.4",
"symplify/phpstan-extensions": "^12.0",
"tomasvotruba/class-leak": "^2.0",
"rector/jack": "^0.2",
"tracy/tracy": "^2.11"
"tomasvotruba/class-leak": "^2.1.5",
"rector/jack": "^1.0",
"tracy/tracy": "^2.12"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameters:

# conditional check to allow various php versions
-
message: '#Comparison operation ">\=" between int<80200, 80599> and (.*?) is always true#'
message: '#Comparison operation ">\=" between int<\d+, \d+> and (.*?) is always true#'
path: src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php

# array filter issue
Expand Down
30 changes: 9 additions & 21 deletions src/DocBlock/UselessDocBlockCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class UselessDocBlockCleaner
/**
* @var string[]
*/
private const CLEANING_REGEXES = [
private const array CLEANING_REGEXES = [
self::TODO_COMMENT_BY_PHPSTORM_REGEX,
self::TODO_IMPLEMENT_METHOD_COMMENT_BY_PHPSTORM_REGEX,
self::COMMENT_CONSTRUCTOR_CLASS_REGEX,
Expand All @@ -28,49 +28,37 @@ final class UselessDocBlockCleaner

/**
* @see https://regex101.com/r/5fQJkz/2
* @var string
*/
private const TODO_IMPLEMENT_METHOD_COMMENT_BY_PHPSTORM_REGEX = '#\/\/ TODO: Implement .*\(\) method.$#';
private const string TODO_IMPLEMENT_METHOD_COMMENT_BY_PHPSTORM_REGEX = '#\/\/ TODO: Implement .*\(\) method.$#';

/**
* @see https://regex101.com/r/zayQpv/1
* @var string
*/
private const TODO_COMMENT_BY_PHPSTORM_REGEX = '#\/\/ TODO: Change the autogenerated stub$#';
private const string TODO_COMMENT_BY_PHPSTORM_REGEX = '#\/\/ TODO: Change the autogenerated stub$#';

/**
* @see https://regex101.com/r/RzTdFH/4
* @var string
*/
private const STANDALONE_DOCBLOCK_CLASS_REGEX = '#(\/\*\*\s+)\*\s+[cC]lass\s+[^\s]*(\s+\*\/)$#';
private const string STANDALONE_DOCBLOCK_CLASS_REGEX = '#(\/\*\*\s+)\*\s+[cC]lass\s+[^\s]*(\s+\*\/)$#';

/**
* @see https://regex101.com/r/RzTdFH/4
* @var string
*/
private const STANDALONE_COMMENT_CLASS_REGEX = '#\/\/\s+(class|trait|interface)\s+\w+$#i';
private const string STANDALONE_COMMENT_CLASS_REGEX = '#\/\/\s+(class|trait|interface)\s+\w+$#i';

/**
* @see https://regex101.com/r/RzTdFH/4
* @var string
*/
private const INLINE_COMMENT_CLASS_REGEX = '#\s\*\s(class|trait|interface)\s+(\w)+$#i';
private const string INLINE_COMMENT_CLASS_REGEX = '#\s\*\s(class|trait|interface)\s+(\w)+$#i';

/**
* @var string
*/
private const COMMENT_CONSTRUCTOR_CLASS_REGEX = '#^(\/\/|(\s|\*)+)(\s\w+\s)?constructor(\.)?$#i';
private const string COMMENT_CONSTRUCTOR_CLASS_REGEX = '#^(\/\/|(\s|\*)+)(\s\w+\s)?constructor(\.)?$#i';

/**
* @see https://regex101.com/r/1kcgR5/1
* @var string
*/
private const DOCTRINE_GENERATED_COMMENT_REGEX = '#^(\/\*{2}\s+?)?(\*|\/\/)\s+This class was generated by the Doctrine ORM\. Add your own custom\r?\n\s+\*\s+repository methods below\.(\s+\*\/)$#';
private const string DOCTRINE_GENERATED_COMMENT_REGEX = '#^(\/\*{2}\s+?)?(\*|\/\/)\s+This class was generated by the Doctrine ORM\. Add your own custom\r?\n\s+\*\s+repository methods below\.(\s+\*\/)$#';

/**
* @var string
*/
private const CLASS_REPRESENTING_REGEX = '#\s\*\sClass\s+representing\s+([\w]+)$#i';
private const string CLASS_REPRESENTING_REGEX = '#\s\*\sClass\s+representing\s+([\w]+)$#i';

public function clearDocTokenContent(Token $currentToken, ?string $classLikeName): string
{
Expand Down
10 changes: 2 additions & 8 deletions src/Enum/BlockBorderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

final class BlockBorderType
{
/**
* @var string
*/
public const OPENER = 'opener';
public const string OPENER = 'opener';

/**
* @var string
*/
public const CLOSER = 'closer';
public const string CLOSER = 'closer';
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
*/
final class RemoveMethodNameDuplicateDescriptionFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Remove docblock descriptions which duplicate their method name';
private const string ERROR_MESSAGE = 'Remove docblock descriptions which duplicate their method name';

private readonly MethodNameResolver $methodNameResolver;

Expand Down
8 changes: 2 additions & 6 deletions src/Fixer/Annotation/RemovePHPStormAnnotationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ final class RemovePHPStormAnnotationFixer extends AbstractSymplifyFixer
{
/**
* @see https://regex101.com/r/nGZBzj/2
* @var string
*/
private const CREATED_BY_PHPSTORM_DOC_REGEX = '#\/\*\*\s+\*\s+Created by PHPStorm(.*?)\*\/#msi';
private const string CREATED_BY_PHPSTORM_DOC_REGEX = '#\/\*\*\s+\*\s+Created by PHPStorm(.*?)\*\/#msi';

/**
* @var string
*/
private const ERROR_MESSAGE = 'Remove "Created by PhpStorm" annotations';
private const string ERROR_MESSAGE = 'Remove "Created by PhpStorm" annotations';

public function __construct(
private readonly TokenReverser $tokenReverser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
*/
final class RemovePropertyVariableNameDescriptionFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Remove useless "$variable" from @var tag';
private const string ERROR_MESSAGE = 'Remove useless "$variable" from @var tag';

/**
* @var string
* @see https://regex101.com/r/2PxeKF/1
*/
private const VAR_REGEX = '#@(?:psalm-|phpstan-)?var#';
private const string VAR_REGEX = '#@(?:psalm-|phpstan-)?var#';

private readonly PropertyNameResolver $propertyNameResolver;

Expand Down
7 changes: 3 additions & 4 deletions src/Fixer/ArrayNotation/ArrayListItemNewlineFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\CodingStandard\Fixer\ArrayNotation;

use Override;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand All @@ -20,10 +21,7 @@
*/
final class ArrayListItemNewlineFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Indexed PHP array item has to have one line per item';
private const string ERROR_MESSAGE = 'Indexed PHP array item has to have one line per item';

public function __construct(
private readonly ArrayItemNewliner $arrayItemNewliner,
Expand All @@ -37,6 +35,7 @@ public function getDefinition(): FixerDefinitionInterface
return new FixerDefinition(self::ERROR_MESSAGE, []);
}

#[Override]
public function getPriority(): int
{
return 40;
Expand Down
7 changes: 3 additions & 4 deletions src/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\CodingStandard\Fixer\ArrayNotation;

use Override;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand All @@ -22,10 +23,7 @@
*/
final class ArrayOpenerAndCloserNewlineFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Indexed PHP array opener [ and closer ] must be on own line';
private const string ERROR_MESSAGE = 'Indexed PHP array opener [ and closer ] must be on own line';

public function __construct(
private readonly ArrayBlockInfoFinder $arrayBlockInfoFinder,
Expand All @@ -44,6 +42,7 @@ public function getDefinition(): FixerDefinitionInterface
*
* @see \PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer::getPriority()
*/
#[Override]
public function getPriority(): int
{
return 34;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\CodingStandard\Fixer\ArrayNotation;

use Override;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand All @@ -22,10 +23,7 @@
*/
final class StandaloneLineInMultilineArrayFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Indexed arrays must have 1 item per line';
private const string ERROR_MESSAGE = 'Indexed arrays must have 1 item per line';

public function __construct(
private readonly ArrayWrapperFactory $arrayWrapperFactory,
Expand All @@ -44,6 +42,7 @@ public function getDefinition(): FixerDefinitionInterface
*
* @see \PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::getPriority()
*/
#[Override]
public function getPriority(): int
{
return 5;
Expand Down
10 changes: 4 additions & 6 deletions src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Symplify\CodingStandard\Fixer\Commenting;

use Nette\Utils\Strings;
use Override;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand All @@ -28,16 +29,12 @@
*/
final class ParamReturnAndVarTagMalformsFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Fixes @param, @return, @var and inline @var annotations broken formats';
private const string ERROR_MESSAGE = 'Fixes @param, @return, @var and inline @var annotations broken formats';

/**
* @var string
* @see https://regex101.com/r/Nlxkd9/1
*/
private const TYPE_ANNOTATION_REGEX = '#@(psalm-|phpstan-)?(param|return|var)#';
private const string TYPE_ANNOTATION_REGEX = '#@(psalm-|phpstan-)?(param|return|var)#';

/**
* @var MalformWorkerInterface[]
Expand Down Expand Up @@ -135,6 +132,7 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void
*
* @see \PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer::getPriority()
*/
#[Override]
public function getPriority(): int
{
return -37;
Expand Down
7 changes: 3 additions & 4 deletions src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\CodingStandard\Fixer\Commenting;

use Override;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand All @@ -19,10 +20,7 @@
*/
final class RemoveUselessDefaultCommentFixer extends AbstractSymplifyFixer
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Remove useless PHPStorm-generated @todo comments, redundant "Class XY" or "gets service" comments etc.';
private const string ERROR_MESSAGE = 'Remove useless PHPStorm-generated @todo comments, redundant "Class XY" or "gets service" comments etc.';

public function __construct(
private readonly UselessDocBlockCleaner $uselessDocBlockCleaner,
Expand All @@ -44,6 +42,7 @@ public function isCandidate(Tokens $tokens): bool
return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]);
}

#[Override]
public function getPriority(): int
{
/** must run before @see \PhpCsFixer\Fixer\Basic\BracesFixer to cleanup spaces */
Expand Down
21 changes: 7 additions & 14 deletions src/Fixer/LineLength/LineLengthFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\CodingStandard\Fixer\LineLength;

use Override;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
use PhpCsFixer\FixerDefinition\FixerDefinition;
Expand All @@ -30,31 +31,22 @@ final class LineLengthFixer extends AbstractSymplifyFixer implements Configurabl
{
/**
* @api
* @var string
*/
public const LINE_LENGTH = 'line_length';
public const string LINE_LENGTH = 'line_length';

/**
* @api
* @var string
*/
public const BREAK_LONG_LINES = 'break_long_lines';
public const string BREAK_LONG_LINES = 'break_long_lines';

/**
* @api
* @var string
*/
public const INLINE_SHORT_LINES = 'inline_short_lines';
public const string INLINE_SHORT_LINES = 'inline_short_lines';

/**
* @var string
*/
private const ERROR_MESSAGE = 'Array items, method parameters, method call arguments, new arguments should be on same/standalone line to fit line length.';
private const string ERROR_MESSAGE = 'Array items, method parameters, method call arguments, new arguments should be on same/standalone line to fit line length.';

/**
* @var int
*/
private const DEFAULT_LINE_LENGHT = 120;
private const int DEFAULT_LINE_LENGHT = 120;

private int $lineLength = self::DEFAULT_LINE_LENGHT;

Expand Down Expand Up @@ -139,6 +131,7 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void
*
* @see \PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer::getPriority()
*/
#[Override]
public function getPriority(): int
{
return 5;
Expand Down
Loading
Loading