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
14 changes: 4 additions & 10 deletions build/build-preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@

final class PreloadBuilder
{
/**
* @var string
*/
private const PRELOAD_FILE_TEMPLATE = <<<'CODE_SAMPLE'
private const string PRELOAD_FILE_TEMPLATE = <<<'CODE_SAMPLE'
<?php

declare(strict_types=1);
Expand Down Expand Up @@ -75,18 +72,15 @@ function isPHPStanTestPreloaded(): bool
}
CODE_SAMPLE;

/**
* @var int
*/
private const PRIORITY_LESS_FILE_POSITION = -1;
private const int PRIORITY_LESS_FILE_POSITION = -1;

/**
* These files are parent to another files, so they have to be included first
* See https://github.com/rectorphp/rector/issues/6709 for more
*
* @var string[]
*/
private const HIGH_PRIORITY_FILES = [
private const array HIGH_PRIORITY_FILES = [
// nikic/php-parser
'Node.php',
'NodeAbstract.php',
Expand Down Expand Up @@ -131,7 +125,7 @@ function isPHPStanTestPreloaded(): bool
*
* @var string[]
*/
private const IN_USE_CLASS_FILES = [
private const array IN_USE_CLASS_FILES = [
'Node/Expr/ArrayItem.php',
'Node/Expr/ClosureUse.php',
'Node/Scalar/EncapsedStringPart.php',
Expand Down
6 changes: 5 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\Utils\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector;

Expand Down Expand Up @@ -39,7 +40,10 @@
])
->withRootFiles()
->withImportNames(removeUnusedImports: true)
->withRules([RemoveRefactorDuplicatedNodeInstanceCheckRector::class, AddSeeTestAnnotationRector::class])
->withRules([
RemoveRefactorDuplicatedNodeInstanceCheckRector::class, AddSeeTestAnnotationRector::class,
AddTypeToConstRector::class,
])
->withSkip([
StringClassNameToClassConstantRector::class,
// tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Rector\Tests\Php83\Rector\ClassConst\AddTypeToConstRector\Fixture;

final class RemoveDocBlockAsUseless
{
/**
* @var int
*/
private const A = 1000;
}

?>
-----
<?php

namespace Rector\Tests\Php83\Rector\ClassConst\AddTypeToConstRector\Fixture;

final class RemoveDocBlockAsUseless
{
private const int A = 1000;
}

?>
9 changes: 3 additions & 6 deletions rules/Arguments/NodeAnalyzer/ArgumentAddingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@
{
/**
* @api
* @var string
*/
public const SCOPE_PARENT_CALL = 'parent_call';
public const string SCOPE_PARENT_CALL = 'parent_call';

/**
* @api
* @var string
*/
public const SCOPE_METHOD_CALL = 'method_call';
public const string SCOPE_METHOD_CALL = 'method_call';

/**
* @api
* @var string
*/
public const SCOPE_CLASS_METHOD = 'class_method';
public const string SCOPE_CLASS_METHOD = 'class_method';

public function __construct(
private NodeNameResolver $nodeNameResolver
Expand Down
5 changes: 1 addition & 4 deletions rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

final readonly class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueInterface
{
/**
* @var string
*/
public const ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';
public const string ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';

/**
* @param int<0, max> $position
Expand Down
10 changes: 2 additions & 8 deletions rules/Assert/Enum/AssertClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

final class AssertClassName
{
/**
* @var string
*/
public const WEBMOZART = 'Webmozart\Assert\Assert';
public const string WEBMOZART = 'Webmozart\Assert\Assert';

/**
* @var string
*/
public const BEBERLEI = 'Assert\Assertion';
public const string BEBERLEI = 'Assert\Assertion';
}
6 changes: 2 additions & 4 deletions rules/Carbon/NodeFactory/CarbonCallFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
final class CarbonCallFactory
{
/**
* @var string
* @see https://regex101.com/r/LLMrFw/1
*/
private const PLUS_MINUS_COUNT_REGEX = '#(?<operator>\+|-)(\\s+)?(?<count>\\d+)(\s+)?(?<unit>seconds|second|sec|minutes|minute|min|hours|hour|days|day|weeks|week|months|month|years|year)#';
private const string PLUS_MINUS_COUNT_REGEX = '#(?<operator>\+|-)(\\s+)?(?<count>\\d+)(\s+)?(?<unit>seconds|second|sec|minutes|minute|min|hours|hour|days|day|weeks|week|months|month|years|year)#';

/**
* @var string
* @see https://regex101.com/r/IhxHTO/1
*/
private const STATIC_DATE_REGEX = '#now|yesterday|today|tomorrow#';
private const string STATIC_DATE_REGEX = '#now|yesterday|today|tomorrow#';

public function createFromDateTimeString(
FullyQualified $carbonFullyQualified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
final class DateFuncCallToCarbonRector extends AbstractRector
{
private const TIME_UNITS = [
private const array TIME_UNITS = [
['weeks', 604800],
['days', 86400],
['hours', 3600],
Expand Down
5 changes: 1 addition & 4 deletions rules/CodeQuality/NodeAnalyzer/LocalPropertyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

final readonly class LocalPropertyAnalyzer
{
/**
* @var string
*/
private const LARAVEL_COLLECTION_CLASS = 'Illuminate\Support\Collection';
private const string LARAVEL_COLLECTION_CLASS = 'Illuminate\Support\Collection';

public function __construct(
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
*/
final class ThrowWithPreviousExceptionRector extends AbstractRector
{
/**
* @var int
*/
private const DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;
private const int DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;

public function __construct(
private readonly ReflectionProvider $reflectionProvider
Expand Down
8 changes: 2 additions & 6 deletions rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
*/
final class JoinStringConcatRector extends AbstractRector
{
/**
* @var int
*/
private const LINE_BREAK_POINT = 100;
private const int LINE_BREAK_POINT = 100;

/**
* @var string
* @see https://regex101.com/r/VaXM1t/1
* @see https://stackoverflow.com/questions/4147646/determine-if-utf-8-text-is-all-ascii
*/
private const ASCII_REGEX = '#[^\x00-\x7F]#';
private const string ASCII_REGEX = '#[^\x00-\x7F]#';

public function getRuleDefinition(): RuleDefinition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
*/
final class ForRepeatedCountToOwnVariableRector extends AbstractRector
{
/**
* @var string
*/
private const COUNTER_NAME = 'counter';
private const string COUNTER_NAME = 'counter';

public function getRuleDefinition(): RuleDefinition
{
Expand Down
2 changes: 1 addition & 1 deletion rules/CodeQuality/Rector/FuncCall/SetTypeToCastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class SetTypeToCastRector extends AbstractRector
/**
* @var array<string, class-string<Cast>>
*/
private const TYPE_TO_CAST = [
private const array TYPE_TO_CAST = [
'array' => Array_::class,
'bool' => Bool_::class,
'boolean' => Bool_::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class SimplifyRegexPatternRector extends AbstractRector
*
* @var array<string, string>
*/
private const COMPLEX_PATTERN_TO_SIMPLE = [
private const array COMPLEX_PATTERN_TO_SIMPLE = [
'[0-9]' => "\d",
'[a-zA-Z0-9_]' => "\w",
'[A-Za-z0-9_]' => "\w",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
final class SimplifyStrposLowerRector extends AbstractRector
{
/**
* @var string
* @see https://regex101.com/r/Jokjt8/1
*/
private const UPPERCASE_REGEX = '#[A-Z]#';
private const string UPPERCASE_REGEX = '#[A-Z]#';

public function getRuleDefinition(): RuleDefinition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ final class SimplifyUselessVariableRector extends AbstractRector implements Conf
{
/**
* @api
* @var string
*/
public const ONLY_DIRECT_ASSIGN = 'only_direct_assign';
public const string ONLY_DIRECT_ASSIGN = 'only_direct_assign';

private bool $onlyDirectAssign = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
*/
final class SimplifyIfElseToTernaryRector extends AbstractRector
{
/**
* @var int
*/
private const LINE_LENGTH_LIMIT = 120;
private const int LINE_LENGTH_LIMIT = 120;

public function __construct(
private readonly BetterStandardPrinter $betterStandardPrinter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
final class AbsolutizeRequireAndIncludePathRector extends AbstractRector
{
/**
* @var string
* @see https://regex101.com/r/N8oLqv/1
*/
private const WINDOWS_DRIVE_REGEX = '#^[a-zA-z]\:[\/\\\]#';
private const string WINDOWS_DRIVE_REGEX = '#^[a-zA-z]\:[\/\\\]#';

public function __construct(
private readonly ValueResolver $valueResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @var string[]
*/
private const RESERVED_CLASS_NAMES = [
private const array RESERVED_CLASS_NAMES = [
'bool',
'false',
'float',
Expand Down
4 changes: 1 addition & 3 deletions rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
final readonly class UseImportNameMatcher
{
/**
* @var string
*
* @see https://regex101.com/r/ZxFSlc/1 for last name, eg: Entity and UniqueEntity
* @see https://regex101.com/r/OLO0Un/1 for inside namespace, eg: ORM for ORM\Id or ORM\Column
*/
private const SHORT_NAME_REGEX = '#^%s(\\\\[\w]+)?$#i';
private const string SHORT_NAME_REGEX = '#^%s(\\\\[\w]+)?$#i';

public function __construct(
private BetterNodeFinder $betterNodeFinder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
final class CatchExceptionNameMatchingTypeRector extends AbstractRector
{
/**
* @var string
* @see https://regex101.com/r/xmfMAX/1
*/
private const STARTS_WITH_ABBREVIATION_REGEX = '#^([A-Za-z]+?)([A-Z]{1}[a-z]{1})([A-Za-z]*)#';
private const string STARTS_WITH_ABBREVIATION_REGEX = '#^([A-Za-z]+?)([A-Z]{1}[a-z]{1})([A-Za-z]*)#';

public function __construct(
private readonly PropertyNaming $propertyNaming,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ final class EncapsedStringsToSprintfRector extends AbstractRector implements Con
{
/**
* @api
* @var string
*/
public const ALWAYS = 'always';
public const string ALWAYS = 'always';

/**
* @var array<string, array<class-string<Type>>>
*/
private const FORMAT_SPECIFIERS = [
private const array FORMAT_SPECIFIERS = [
'%s' => ['PHPStan\Type\StringType'],
'%d' => [
'PHPStan\Type\Constant\ConstantIntegerType',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class VersionCompareFuncCallToConstantRector extends AbstractRector
/**
* @var array<string, class-string<BinaryOp>>
*/
private const OPERATOR_TO_COMPARISON = [
private const array OPERATOR_TO_COMPARISON = [
'=' => Identical::class,
'==' => Identical::class,
'eq' => Identical::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
final class SimplifyQuoteEscapeRector extends AbstractRector
{
/**
* @var string
* @see https://regex101.com/r/qEkCe9/2
*/
private const ESCAPED_CHAR_REGEX = '#\\\\|\$|\\n|\\t#sim';
private const string ESCAPED_CHAR_REGEX = '#\\\\|\$|\\n|\\t#sim';

/**
* @var string
* @see https://alvinalexander.com/php/how-to-remove-non-printable-characters-in-string-regex/
* @see https://regex101.com/r/lGUhRb/1
*/
private const HAS_NON_PRINTABLE_CHARS = '#[\x00-\x1F\x80-\xFF]#';
private const string HAS_NON_PRINTABLE_CHARS = '#[\x00-\x1F\x80-\xFF]#';

private bool $hasChanged = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
final class UseClassKeywordForClassNameResolutionRector extends AbstractRector
{
/**
* @var string
* @see https://regex101.com/r/Vv41Qr/1/
*/
private const CLASS_BEFORE_STATIC_ACCESS_REGEX = '#(?<class_name>[\\\\a-zA-Z0-9_\\x80-\\xff]*)::#';
private const string CLASS_BEFORE_STATIC_ACCESS_REGEX = '#(?<class_name>[\\\\a-zA-Z0-9_\\x80-\\xff]*)::#';

public function __construct(
private readonly ReflectionProvider $reflectionProvider
Expand Down
2 changes: 1 addition & 1 deletion rules/CodingStyle/ValueObject/ObjectMagicMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ObjectMagicMethods
/**
* @var string[]
*/
public const METHOD_NAMES = [
public const array METHOD_NAMES = [
'__call',
'__callStatic',
MethodName::CLONE,
Expand Down
2 changes: 1 addition & 1 deletion rules/DeadCode/PhpDoc/Guard/StandaloneTypeRemovalGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class StandaloneTypeRemovalGuard
/**
* @var string[]
*/
private const ALLOWED_TYPES = ['false', 'true'];
private const array ALLOWED_TYPES = ['false', 'true'];

public function isLegal(TypeNode $typeNode, Node $node): bool
{
Expand Down
Loading