Skip to content

Commit

Permalink
[DX] Try unused public const PHPStan rule (#2595)
Browse files Browse the repository at this point in the history
* remove unused TEAR_DOWN const

* make CLASS_NAME_REGEX private

* remove unused FOLLOW_SYMLINKS

* make TREAT_AS_NON_EMPTY api

* remove deprecated ENABLE_EDITORCONFIG

* remove unused OUTPUT_FORMAT_SHORT const

* make SetList part of API

* more API

* remove unused RELEASE_DATE

* more API

* make use of Name constants in FileDiff

* remove unused FILE const

* remove deprecated and unused PREVIOUS_STATEMENT and CURRENT_STATEMENT

* remove unused SPACE_OR_ASTERISK_REGEX

* make CLOSING_DOCBLOCK_REGEX private

* cleanup

* make DOC_INDENTATION an api
  • Loading branch information
TomasVotruba committed Jun 30, 2022
1 parent 143f743 commit ed92724
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 92 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"symplify/easy-coding-standard": "^11.0",
"symplify/monorepo-builder": "^11.0",
"symplify/phpstan-extensions": "^11.0",
"symplify/phpstan-rules": "^11.0",
"symplify/phpstan-rules": "dev-main",
"symplify/rule-doc-generator": "^11.0",
"symplify/vendor-patches": "^11.0"
},
Expand Down Expand Up @@ -183,5 +183,7 @@
"rector/extension-installer": true,
"cweagans/composer-patches": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class PhpDocInfoPrinter
* @var string
* @see https://regex101.com/r/Ab0Vey/1
*/
public const CLOSING_DOCBLOCK_REGEX = '#\*\/(\s+)?$#';
private const CLOSING_DOCBLOCK_REGEX = '#\*\/(\s+)?$#';

/**
* @var string
Expand Down
6 changes: 0 additions & 6 deletions packages/Comments/NodeDocBlock/DocBlockUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

final class DocBlockUpdater
{
/**
* @var string
* @see https://regex101.com/r/VdaVGL/1
*/
public const SPACE_OR_ASTERISK_REGEX = '#(\s|\*)+#';

public function __construct(
private readonly PhpDocInfoPrinter $phpDocInfoPrinter
) {
Expand Down
25 changes: 2 additions & 23 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@ final class AttributeKey
*/
public const NEXT_NODE = 'next';

/**
* @deprecated Instead of tree climbing without context, hook into parent node that contains the stmts directly.
* E.g. FunctionLike, If_, While_ etc.
* @var string
*/
public const PREVIOUS_STATEMENT = 'previousExpression';

/**
* @deprecated Instead of tree climbing without context, hook into parent node that contains the stmts directly.
* E.g. FunctionLike, If_, While_ etc.
* Use @see \Rector\Core\PhpParser\Node\BetterNodeFinder::resolveCurrentStatement() instead if actually needed
* @var string
*/
public const CURRENT_STATEMENT = 'currentExpression';

/**
* Internal php-parser name.
* Do not change this even if you want!
Expand All @@ -102,6 +87,8 @@ final class AttributeKey
public const NAMESPACED_NAME = 'namespacedName';

/**
* @api
*
* Internal php-parser name.
* Do not change this even if you want!
*
Expand Down Expand Up @@ -150,14 +137,6 @@ final class AttributeKey
*/
public const FUNC_ARGS_TRAILING_COMMA = 'trailing_comma';

/**
* Contains current file object
* @see \Rector\Core\ValueObject\Application\File
*
* @var string
*/
public const FILE = 'file';

/**
* Helps with infinite loop detection
* @var string
Expand Down
6 changes: 6 additions & 0 deletions packages/Parallel/ValueObject/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Parallel\ValueObject;

/**
* @api
* Helpers constant for passing constant names around
*/
final class Name
Expand Down Expand Up @@ -43,4 +44,9 @@ final class Name
* @var string
*/
public const RECTOR_CLASS = 'rector_class';

/**
* @var string
*/
public const RECTORS_WITH_LINE_CHANGES = 'rectors_with_line_changes';
}
3 changes: 3 additions & 0 deletions packages/Set/ValueObject/LevelSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Rector\Set\Contract\SetListInterface;

/**
* @api
*/
final class LevelSetList implements SetListInterface
{
/**
Expand Down
3 changes: 3 additions & 0 deletions packages/Set/ValueObject/SetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Rector\Set\Contract\SetListInterface;

/**
* @api
*/
final class SetList implements SetListInterface
{
/**
Expand Down
3 changes: 3 additions & 0 deletions rules/Arguments/NodeAnalyzer/ArgumentAddingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
final class ArgumentAddingScope
{
/**
* @api
* @var string
*/
public const SCOPE_PARENT_CALL = 'parent_call';

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

/**
* @api
* @var string
*/
public const SCOPE_CLASS_METHOD = 'class_method';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
final class OrderAttributesRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const ALPHABETICALLY = 'alphabetically';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
final class RemoveUnusedPrivatePropertyRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const REMOVE_ASSIGN_SIDE_EFFECT = 'remove_assign_side_effect';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ public function refactor(Node $node): ?Node
/**
* @param Stmt[] $followingStmts
*/
public function isFollowingStatementStaticClosure(array $followingStmts): bool
private function isFollowingStatementStaticClosure(array $followingStmts): bool
{
return count($followingStmts) > 0
&& $followingStmts[0] instanceof Expression
if ($followingStmts === []) {
return false;
}

return $followingStmts[0] instanceof Expression
&& $followingStmts[0]->expr instanceof Closure
&& $followingStmts[0]->expr->static;
}
Expand Down
1 change: 1 addition & 0 deletions rules/Php74/Rector/Property/TypedPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
final class TypedPropertyRector extends AbstractScopeAwareRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
{
/**
* @api
* @var string
*/
public const INLINE_PUBLIC = 'inline_public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
final class DoctrineAnnotationClassToAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface
{
/**
* @api
* @var string
*/
public const REMOVE_ANNOTATIONS = 'remove_annotations';
Expand Down
1 change: 1 addition & 0 deletions rules/Strict/Rector/AbstractFalsyScalarRuleFixerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
abstract class AbstractFalsyScalarRuleFixerRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
final public const TREAT_AS_NON_EMPTY = 'treat_as_non_empty';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
final class AddVoidReturnTypeWhereNoReturnRector extends AbstractRector implements MinPhpVersionInterface, AllowEmptyConfigurableRectorInterface
{
/**
* @api
* @var string using phpdoc instead of a native void type can ease the migration path for consumers of code being processed.
*/
public const USE_PHPDOC = 'use_phpdoc';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
final class TypedPropertyFromAssignsRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const INLINE_PUBLIC = 'inline_public';
Expand Down
5 changes: 0 additions & 5 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ final class VersionResolver
*/
public const PACKAGE_VERSION = '@package_version@';

/**
* @var string
*/
public const RELEASE_DATE = '@release_date@';

/**
* @var int
*/
Expand Down
17 changes: 0 additions & 17 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,11 @@ final class Option
*/
public const TEMPLATE_TYPE = 'template-type';

/**
* @deprecated
* @var string
*/
public const ENABLE_EDITORCONFIG = 'enable_editorconfig';

/**
* @var string
*/
public const AUTOLOAD_FILE_SHORT = 'a';

/**
* @var string
*/
public const OUTPUT_FORMAT_SHORT = 'o';

/**
* @var string
*/
Expand Down Expand Up @@ -219,12 +208,6 @@ final class Option
*/
public const PARALLEL_TIMEOUT_IN_SECONDS = 'parallel-timeout-in-seconds';

/**
* @deprecated Rector should not run on external unknown sources, as PHPStan needs to know about paths to reflect on those. Instead, provide the path directly.
* @var string
*/
public const FOLLOW_SYMLINKS = 'follow-symlinks';

/**
* @var string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/RectorAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class RectorAssert
* @see https://regex101.com/r/PYQaPF/1
* @var string
*/
public const CLASS_NAME_REGEX = '#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*$#';
private const CLASS_NAME_REGEX = '#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*$#';

/**
* Assert value is valid class name
Expand Down
6 changes: 0 additions & 6 deletions src/ValueObject/MethodName.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ final class MethodName
*/
public const SET_UP = 'setUp';

/**
* Mostly used in unit tests
* @var string
*/
public const TEAR_DOWN = 'tearDown';

/**
* @var string
*/
Expand Down
3 changes: 3 additions & 0 deletions src/ValueObject/PhpVersionFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Rector\Core\ValueObject;

/**
* @api
*/
final class PhpVersionFeature
{
/**
Expand Down
37 changes: 9 additions & 28 deletions src/ValueObject/Reporting/FileDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nette\Utils\Strings;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Parallel\ValueObject\Name;
use Symplify\EasyParallel\Contract\SerializableInterface;
use Webmozart\Assert\Assert;

Expand All @@ -23,26 +24,6 @@ final class FileDiff implements SerializableInterface
*/
private const FIRST_LINE_KEY = 'first_line';

/**
* @var string
*/
private const KEY_RELATIVE_FILE_PATH = 'relative_file_path';

/**
* @var string
*/
private const KEY_DIFF = 'diff';

/**
* @var string
*/
private const KEY_DIFF_CONSOLE_FORMATTED = 'diff_console_formatted';

/**
* @var string
*/
private const KEY_RECTORS_WITH_LINE_CHANGES = 'rectors_with_line_changes';

/**
* @param RectorWithLineChange[] $rectorsWithLineChanges
*/
Expand Down Expand Up @@ -110,10 +91,10 @@ public function getFirstLineNumber(): ?int
public function jsonSerialize(): array
{
return [
self::KEY_RELATIVE_FILE_PATH => $this->relativeFilePath,
self::KEY_DIFF => $this->diff,
self::KEY_DIFF_CONSOLE_FORMATTED => $this->diffConsoleFormatted,
self::KEY_RECTORS_WITH_LINE_CHANGES => $this->rectorsWithLineChanges,
Name::RELATIVE_FILE_PATH => $this->relativeFilePath,
Name::DIFF => $this->diff,
Name::DIFF_CONSOLE_FORMATTED => $this->diffConsoleFormatted,
Name::RECTORS_WITH_LINE_CHANGES => $this->rectorsWithLineChanges,
];
}

Expand All @@ -124,14 +105,14 @@ public static function decode(array $json): SerializableInterface
{
$rectorWithLineChanges = [];

foreach ($json[self::KEY_RECTORS_WITH_LINE_CHANGES] as $rectorWithLineChangesJson) {
foreach ($json[Name::RECTORS_WITH_LINE_CHANGES] as $rectorWithLineChangesJson) {
$rectorWithLineChanges[] = RectorWithLineChange::decode($rectorWithLineChangesJson);
}

return new self(
$json[self::KEY_RELATIVE_FILE_PATH],
$json[self::KEY_DIFF],
$json[self::KEY_DIFF_CONSOLE_FORMATTED],
$json[Name::RELATIVE_FILE_PATH],
$json[Name::DIFF],
$json[Name::DIFF_CONSOLE_FORMATTED],
$rectorWithLineChanges,
);
}
Expand Down

0 comments on commit ed92724

Please sign in to comment.