diff --git a/composer.json b/composer.json index 12fa649812c..666260b66da 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "amphp/phpunit-util": "^3", "bamarni/composer-bin-plugin": "^1.4", "brianium/paratest": "^6.9", + "dg/bypass-finals": "^1.5", "mockery/mockery": "^1.5", "nunomaduro/mock-final-classes": "^1.1", "php-parallel-lint/php-parallel-lint": "^1.2", diff --git a/examples/TemplateChecker.php b/examples/TemplateChecker.php index 7fec45544dc..4e911dd268d 100644 --- a/examples/TemplateChecker.php +++ b/examples/TemplateChecker.php @@ -30,7 +30,7 @@ use function strtolower; use function trim; -class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer +final class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer { final public const VIEW_CLASS = 'Your\\View\\Class'; @@ -148,7 +148,7 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt, /** * @param array $stmts */ - protected function checkWithViewClass(Context $context, array $stmts): void + private function checkWithViewClass(Context $context, array $stmts): void { $pseudo_method_stmts = []; diff --git a/examples/TemplateScanner.php b/examples/TemplateScanner.php index 681bf61bdc7..254b06dc338 100644 --- a/examples/TemplateScanner.php +++ b/examples/TemplateScanner.php @@ -14,7 +14,7 @@ use function preg_match; use function trim; -class TemplateScanner extends Psalm\Internal\Scanner\FileScanner +final class TemplateScanner extends Psalm\Internal\Scanner\FileScanner { final public const VIEW_CLASS = 'Your\\View\\Class'; diff --git a/examples/plugins/ClassUnqualifier.php b/examples/plugins/ClassUnqualifier.php index 97cecee648c..d2b05332329 100644 --- a/examples/plugins/ClassUnqualifier.php +++ b/examples/plugins/ClassUnqualifier.php @@ -12,7 +12,7 @@ use function strpos; use function strtolower; -class ClassUnqualifier implements AfterClassLikeExistenceCheckInterface +final class ClassUnqualifier implements AfterClassLikeExistenceCheckInterface { public static function afterClassLikeExistenceCheck( AfterClassLikeExistenceCheckEvent $event diff --git a/examples/plugins/FunctionCasingChecker.php b/examples/plugins/FunctionCasingChecker.php index f4d8c6a2e3e..56ec8983203 100644 --- a/examples/plugins/FunctionCasingChecker.php +++ b/examples/plugins/FunctionCasingChecker.php @@ -21,7 +21,7 @@ /** * Checks that functions and methods are correctly-cased */ -class FunctionCasingChecker implements AfterFunctionCallAnalysisInterface, AfterMethodCallAnalysisInterface +final class FunctionCasingChecker implements AfterFunctionCallAnalysisInterface, AfterMethodCallAnalysisInterface { public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $event): void { @@ -99,6 +99,6 @@ public static function afterFunctionCallAnalysis(AfterFunctionCallAnalysisEvent } } -class IncorrectFunctionCasing extends PluginIssue +final class IncorrectFunctionCasing extends PluginIssue { } diff --git a/examples/plugins/InternalChecker.php b/examples/plugins/InternalChecker.php index a5c6306bab0..0b2ea575187 100644 --- a/examples/plugins/InternalChecker.php +++ b/examples/plugins/InternalChecker.php @@ -12,7 +12,7 @@ use function strpos; -class InternalChecker implements AfterClassLikeAnalysisInterface +final class InternalChecker implements AfterClassLikeAnalysisInterface { /** @return null|false */ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event): ?bool diff --git a/examples/plugins/PreventFloatAssignmentChecker.php b/examples/plugins/PreventFloatAssignmentChecker.php index 18b5630efbc..5bc7b0765bb 100644 --- a/examples/plugins/PreventFloatAssignmentChecker.php +++ b/examples/plugins/PreventFloatAssignmentChecker.php @@ -12,7 +12,7 @@ /** * Prevents any assignment to a float value */ -class PreventFloatAssignmentChecker implements AfterExpressionAnalysisInterface +final class PreventFloatAssignmentChecker implements AfterExpressionAnalysisInterface { /** * Called after an expression has been checked @@ -40,6 +40,6 @@ public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $eve } } -class NoFloatAssignment extends PluginIssue +final class NoFloatAssignment extends PluginIssue { } diff --git a/examples/plugins/SafeArrayKeyChecker.php b/examples/plugins/SafeArrayKeyChecker.php index 5ea69772535..0360ed79155 100644 --- a/examples/plugins/SafeArrayKeyChecker.php +++ b/examples/plugins/SafeArrayKeyChecker.php @@ -7,7 +7,7 @@ use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent; use Psalm\Plugin\EventHandler\RemoveTaintsInterface; -class SafeArrayKeyChecker implements RemoveTaintsInterface +final class SafeArrayKeyChecker implements RemoveTaintsInterface { /** * Called to see what taints should be removed diff --git a/examples/plugins/StringChecker.php b/examples/plugins/StringChecker.php index 070bcde5ac4..1ce7a814086 100644 --- a/examples/plugins/StringChecker.php +++ b/examples/plugins/StringChecker.php @@ -16,7 +16,7 @@ use function strpos; use function strtolower; -class StringChecker implements AfterExpressionAnalysisInterface +final class StringChecker implements AfterExpressionAnalysisInterface { /** * Called after an expression has been checked diff --git a/examples/plugins/composer-based/echo-checker/EchoChecker.php b/examples/plugins/composer-based/echo-checker/EchoChecker.php index 668206c26e3..642e0a53e9c 100644 --- a/examples/plugins/composer-based/echo-checker/EchoChecker.php +++ b/examples/plugins/composer-based/echo-checker/EchoChecker.php @@ -11,7 +11,7 @@ use Psalm\Type\Atomic\TLiteralString; use Psalm\Type\Atomic\TString; -class EchoChecker implements AfterStatementAnalysisInterface +final class EchoChecker implements AfterStatementAnalysisInterface { /** * Called after a statement has been checked diff --git a/examples/plugins/composer-based/echo-checker/PluginEntryPoint.php b/examples/plugins/composer-based/echo-checker/PluginEntryPoint.php index 4d6102281e4..e83927e0d04 100644 --- a/examples/plugins/composer-based/echo-checker/PluginEntryPoint.php +++ b/examples/plugins/composer-based/echo-checker/PluginEntryPoint.php @@ -6,7 +6,7 @@ use Psalm\Plugin\RegistrationInterface; use SimpleXMLElement; -class PluginEntryPoint implements PluginEntryPointInterface +final class PluginEntryPoint implements PluginEntryPointInterface { public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null): void { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 748be83439b..4f2c25cff79 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ */ - protected array $universal_object_crates; + private array $universal_object_crates; /** * @var static|null @@ -223,7 +223,7 @@ class Config protected ?ProjectFileFilter $project_files = null; - protected ?ProjectFileFilter $extra_files = null; + private ?ProjectFileFilter $extra_files = null; /** * The base directory of this config file @@ -427,7 +427,7 @@ class Config private ?IncludeCollector $include_collector = null; - protected ?TaintAnalysisFileFilter $taint_analysis_ignored_files = null; + private ?TaintAnalysisFileFilter $taint_analysis_ignored_files = null; /** * @var bool whether to emit a backtrace of emitted issues to stderr @@ -567,7 +567,7 @@ class Config public array $config_warnings = []; /** @internal */ - protected function __construct() + private function __construct() { self::$instance = $this; $this->eventDispatcher = new EventDispatcher(); diff --git a/src/Psalm/Exception/DocblockParseException.php b/src/Psalm/Exception/DocblockParseException.php index 433f6632d2e..306c7eeb8dc 100644 --- a/src/Psalm/Exception/DocblockParseException.php +++ b/src/Psalm/Exception/DocblockParseException.php @@ -6,6 +6,6 @@ use Exception; -class DocblockParseException extends Exception +final class DocblockParseException extends Exception { } diff --git a/src/Psalm/Internal/Analyzer/FileAnalyzer.php b/src/Psalm/Internal/Analyzer/FileAnalyzer.php index 62aeac08f2f..85b2b57592f 100644 --- a/src/Psalm/Internal/Analyzer/FileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FileAnalyzer.php @@ -41,13 +41,13 @@ * @internal * @psalm-consistent-constructor */ -class FileAnalyzer extends SourceAnalyzer +final class FileAnalyzer extends SourceAnalyzer { use CanAlias; - protected ?string $root_file_path = null; + private ?string $root_file_path = null; - protected ?string $root_file_name = null; + private ?string $root_file_name = null; /** * @var array diff --git a/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php b/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php index a6bac10d51a..7a9a50bdc25 100644 --- a/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php @@ -35,7 +35,7 @@ final class NamespaceAnalyzer extends SourceAnalyzer * * @var array> */ - protected static array $public_namespace_constants = []; + private static array $public_namespace_constants = []; public function __construct( private readonly Namespace_ $namespace, /** diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index c4ff79c024f..ef9e130aad7 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -957,7 +957,7 @@ public function addExtraFile(string $file_path): void /** * @return list */ - protected function getDiffFiles(): array + private function getDiffFiles(): array { if (!$this->parser_cache_provider || !$this->project_cache_provider) { throw new UnexpectedValueException('Parser cache provider cannot be null here'); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 560305843d4..79e102de0e5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -928,7 +928,7 @@ private static function processIrreconcilableFunctionCall( * @param PhpParser\Node\Expr\FuncCall|PhpParser\Node\Expr\MethodCall|PhpParser\Node\Expr\StaticCall $expr * @return list>>> */ - protected static function processCustomAssertion( + private static function processCustomAssertion( PhpParser\Node\Expr $expr, ?string $this_class_name, FileSource $source, @@ -1230,7 +1230,7 @@ protected static function processCustomAssertion( /** * @return list */ - protected static function getInstanceOfAssertions( + private static function getInstanceOfAssertions( PhpParser\Node\Expr\Instanceof_ $stmt, ?string $this_class_name, FileSource $source, @@ -1295,7 +1295,7 @@ protected static function getInstanceOfAssertions( /** * @param Identical|Equal|NotIdentical|NotEqual $conditional */ - protected static function hasNullVariable( + private static function hasNullVariable( PhpParser\Node\Expr\BinaryOp $conditional, FileSource $source, ): ?int { @@ -1366,7 +1366,7 @@ public static function hasTrueVariable( /** * @param Identical|Equal|NotIdentical|NotEqual $conditional */ - protected static function hasEmptyArrayVariable( + private static function hasEmptyArrayVariable( PhpParser\Node\Expr\BinaryOp $conditional, ): ?int { if ($conditional->right instanceof PhpParser\Node\Expr\Array_ @@ -1387,7 +1387,7 @@ protected static function hasEmptyArrayVariable( /** * @param Identical|Equal|NotIdentical|NotEqual $conditional */ - protected static function hasGetTypeCheck( + private static function hasGetTypeCheck( PhpParser\Node\Expr\BinaryOp $conditional, ): false|int { if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall @@ -1414,7 +1414,7 @@ protected static function hasGetTypeCheck( /** * @param Identical|Equal|NotIdentical|NotEqual $conditional */ - protected static function hasGetDebugTypeCheck( + private static function hasGetDebugTypeCheck( PhpParser\Node\Expr\BinaryOp $conditional, ): false|int { if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall @@ -1443,7 +1443,7 @@ protected static function hasGetDebugTypeCheck( /** * @param Identical|Equal|NotIdentical|NotEqual $conditional */ - protected static function hasGetClassCheck( + private static function hasGetClassCheck( PhpParser\Node\Expr\BinaryOp $conditional, FileSource $source, ): false|int { @@ -1535,7 +1535,7 @@ protected static function hasGetClassCheck( /** * @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional */ - protected static function hasNonEmptyCountEqualityCheck( + private static function hasNonEmptyCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ?int &$min_count, ): false|int { @@ -1576,7 +1576,7 @@ protected static function hasNonEmptyCountEqualityCheck( /** * @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional */ - protected static function hasLessThanCountEqualityCheck( + private static function hasLessThanCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ?int &$max_count, ): false|int { @@ -1624,7 +1624,7 @@ protected static function hasLessThanCountEqualityCheck( /** * @param Equal|Identical|NotEqual|NotIdentical $conditional */ - protected static function hasCountEqualityCheck( + private static function hasCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ?int &$count, ): false|int { @@ -1656,7 +1656,7 @@ protected static function hasCountEqualityCheck( /** * @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional */ - protected static function hasSuperiorNumberCheck( + private static function hasSuperiorNumberCheck( FileSource $source, PhpParser\Node\Expr\BinaryOp $conditional, ?int &$literal_value_comparison, @@ -1715,7 +1715,7 @@ protected static function hasSuperiorNumberCheck( /** * @param PhpParser\Node\Expr\BinaryOp\Smaller|PhpParser\Node\Expr\BinaryOp\SmallerOrEqual $conditional */ - protected static function hasInferiorNumberCheck( + private static function hasInferiorNumberCheck( FileSource $source, PhpParser\Node\Expr\BinaryOp $conditional, ?int &$literal_value_comparison, @@ -1774,7 +1774,7 @@ protected static function hasInferiorNumberCheck( /** * @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional */ - protected static function hasReconcilableNonEmptyCountEqualityCheck( + private static function hasReconcilableNonEmptyCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ): false|int { $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall @@ -1795,7 +1795,7 @@ protected static function hasReconcilableNonEmptyCountEqualityCheck( /** * @param Identical|Equal|NotIdentical|NotEqual $conditional */ - protected static function hasTypedValueComparison( + private static function hasTypedValueComparison( PhpParser\Node\Expr\BinaryOp $conditional, FileSource $source, ): false|int { @@ -1829,7 +1829,7 @@ protected static function hasTypedValueComparison( return false; } - protected static function hasIsACheck( + private static function hasIsACheck( PhpParser\Node\Expr\FuncCall $stmt, StatementsAnalyzer $source, ): bool { @@ -1925,7 +1925,7 @@ private static function handleIsTypeCheck( return $if_types; } - protected static function hasCallableCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasCallableCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'is_callable'; } @@ -1933,7 +1933,7 @@ protected static function hasCallableCheck(PhpParser\Node\Expr\FuncCall $stmt): /** * @return Reconciler::RECONCILIATION_* */ - protected static function hasClassExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): int + private static function hasClassExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): int { if ($stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'class_exists' @@ -1959,7 +1959,7 @@ protected static function hasClassExistsCheck(PhpParser\Node\Expr\FuncCall $stmt /** * @return 0|1|2 */ - protected static function hasTraitExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): int + private static function hasTraitExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): int { if ($stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'trait_exists' @@ -1982,22 +1982,22 @@ protected static function hasTraitExistsCheck(PhpParser\Node\Expr\FuncCall $stmt return 0; } - protected static function hasEnumExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasEnumExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'enum_exists'; } - protected static function hasInterfaceExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasInterfaceExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'interface_exists'; } - protected static function hasFunctionExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasFunctionExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'function_exists'; } - protected static function hasInArrayCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasInArrayCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { if ($stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'in_array' @@ -2015,13 +2015,13 @@ protected static function hasInArrayCheck(PhpParser\Node\Expr\FuncCall $stmt): b return false; } - protected static function hasNonEmptyCountCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasNonEmptyCountCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { return $stmt->name instanceof PhpParser\Node\Name && in_array(strtolower($stmt->name->getFirst()), ['count', 'sizeof']); } - protected static function hasArrayKeyExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool + private static function hasArrayKeyExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'array_key_exists'; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index 25b9f104cb3..f53816e5814 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -76,7 +76,7 @@ /** * @internal */ -class CallAnalyzer +abstract class CallAnalyzer { public static function collectSpecialInformation( FunctionLikeAnalyzer $source, diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index be5d5e48762..8f4d2e4c9e6 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -96,9 +96,9 @@ */ final class StatementsAnalyzer extends SourceAnalyzer { - protected FileAnalyzer $file_analyzer; + private readonly FileAnalyzer $file_analyzer; - protected Codebase $codebase; + private readonly Codebase $codebase; /** * @var array diff --git a/src/Psalm/Internal/Codebase/Populator.php b/src/Psalm/Internal/Codebase/Populator.php index 338d2278e74..1a5c2935503 100644 --- a/src/Psalm/Internal/Codebase/Populator.php +++ b/src/Psalm/Internal/Codebase/Populator.php @@ -865,7 +865,7 @@ private function inheritConstantsFromTrait( } } - protected function inheritMethodsFromParent( + private function inheritMethodsFromParent( ClassLikeStorage $storage, ClassLikeStorage $parent_storage, ): void { diff --git a/src/Psalm/Internal/Codebase/VariableUseGraph.php b/src/Psalm/Internal/Codebase/VariableUseGraph.php index f17154c5a1f..615f7482ee9 100644 --- a/src/Psalm/Internal/Codebase/VariableUseGraph.php +++ b/src/Psalm/Internal/Codebase/VariableUseGraph.php @@ -17,7 +17,7 @@ final class VariableUseGraph extends DataFlowGraph { /** @var array> */ - protected array $backward_edges = []; + private array $backward_edges = []; /** @var array */ private array $nodes = []; diff --git a/src/Psalm/Internal/Diff/AstDiffer.php b/src/Psalm/Internal/Diff/AstDiffer.php index fcc2bd25edc..3c889711585 100644 --- a/src/Psalm/Internal/Diff/AstDiffer.php +++ b/src/Psalm/Internal/Diff/AstDiffer.php @@ -21,7 +21,7 @@ * * @internal */ -class AstDiffer +final class AstDiffer { /** * @param Closure(Stmt, Stmt, string, string, bool=): bool $is_equal @@ -29,7 +29,7 @@ class AstDiffer * @param array $b * @return array{0:non-empty-list>, 1: int, 2: int, 3: array} */ - protected static function calculateTrace( + private static function calculateTrace( Closure $is_equal, array $a, array $b, @@ -81,7 +81,7 @@ protected static function calculateTrace( * @return list * @psalm-pure */ - protected static function extractDiff(array $trace, int $x, int $y, array $a, array $b, array $bc): array + private static function extractDiff(array $trace, int $x, int $y, array $a, array $b, array $bc): array { $result = []; for ($d = count($trace) - 1; $d >= 0; --$d) { diff --git a/src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php b/src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php index aef34adfee4..0da2ea1dc62 100644 --- a/src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php +++ b/src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php @@ -28,7 +28,7 @@ final class BuildInfoCollector /** * Read environment variables. */ - protected array $readEnv = []; + private array $readEnv = []; public function __construct( /** @@ -70,7 +70,7 @@ public function collect(): array * @return $this * @psalm-suppress PossiblyUndefinedStringArrayOffset */ - protected function fillTravisCi(): self + private function fillTravisCi(): self { if (isset($this->env['TRAVIS']) && $this->env['TRAVIS'] && isset($this->env['TRAVIS_JOB_ID'])) { $this->readEnv['CI_JOB_ID'] = $this->env['TRAVIS_JOB_ID']; @@ -113,7 +113,7 @@ protected function fillTravisCi(): self * * @return $this */ - protected function fillCircleCi(): self + private function fillCircleCi(): self { if (isset($this->env['CIRCLECI']) && $this->env['CIRCLECI'] && isset($this->env['CIRCLE_BUILD_NUM'])) { $this->env['CI_BUILD_NUMBER'] = $this->env['CIRCLE_BUILD_NUM']; @@ -146,7 +146,7 @@ protected function fillCircleCi(): self * @psalm-suppress PossiblyUndefinedStringArrayOffset * @return $this */ - protected function fillAppVeyor(): self + private function fillAppVeyor(): self { if (isset($this->env['APPVEYOR']) && $this->env['APPVEYOR'] && isset($this->env['APPVEYOR_BUILD_NUMBER'])) { $this->readEnv['CI_BUILD_NUMBER'] = $this->env['APPVEYOR_BUILD_NUMBER']; @@ -193,7 +193,7 @@ protected function fillAppVeyor(): self * * @return $this */ - protected function fillJenkins(): self + private function fillJenkins(): self { if (isset($this->env['JENKINS_URL']) && isset($this->env['BUILD_NUMBER'])) { $this->readEnv['CI_BUILD_NUMBER'] = $this->env['BUILD_NUMBER']; @@ -217,7 +217,7 @@ protected function fillJenkins(): self * @psalm-suppress PossiblyUndefinedStringArrayOffset * @return $this */ - protected function fillScrutinizer(): self + private function fillScrutinizer(): self { if (isset($this->env['SCRUTINIZER']) && $this->env['SCRUTINIZER']) { $this->readEnv['CI_JOB_ID'] = $this->env['SCRUTINIZER_INSPECTION_UUID']; @@ -251,7 +251,7 @@ protected function fillScrutinizer(): self * @return $this * @psalm-suppress PossiblyUndefinedStringArrayOffset */ - protected function fillGithubActions(): BuildInfoCollector + private function fillGithubActions(): BuildInfoCollector { if (isset($this->env['GITHUB_ACTIONS'])) { $this->env['CI_NAME'] = 'github-actions'; diff --git a/src/Psalm/Internal/ExecutionEnvironment/GitInfoCollector.php b/src/Psalm/Internal/ExecutionEnvironment/GitInfoCollector.php index e23f5781a06..f659fef639d 100644 --- a/src/Psalm/Internal/ExecutionEnvironment/GitInfoCollector.php +++ b/src/Psalm/Internal/ExecutionEnvironment/GitInfoCollector.php @@ -29,7 +29,7 @@ final class GitInfoCollector /** * Git command. */ - protected SystemCommandExecutor $executor; + private readonly SystemCommandExecutor $executor; /** * Constructor. @@ -58,7 +58,7 @@ public function collect(): GitInfo * * @throws RuntimeException */ - protected function collectBranch(): string + private function collectBranch(): string { $branchesResult = $this->executor->execute('git branch'); @@ -78,7 +78,7 @@ protected function collectBranch(): string * * @throws RuntimeException */ - protected function collectCommit(): CommitInfo + private function collectCommit(): CommitInfo { $commitResult = $this->executor->execute('git log -1 --pretty=format:%H%n%aN%n%ae%n%cN%n%ce%n%s%n%at'); @@ -104,7 +104,7 @@ protected function collectCommit(): CommitInfo * @throws RuntimeException * @return list */ - protected function collectRemotes(): array + private function collectRemotes(): array { $remotesResult = $this->executor->execute('git remote -v'); diff --git a/src/Psalm/Internal/LanguageServer/LanguageServer.php b/src/Psalm/Internal/LanguageServer/LanguageServer.php index 30e8758c504..df2f691cd68 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageServer.php +++ b/src/Psalm/Internal/LanguageServer/LanguageServer.php @@ -118,10 +118,10 @@ final class LanguageServer extends Dispatcher /** * The AMP Delay token */ - protected string $versionedAnalysisDelayToken = ''; + private string $versionedAnalysisDelayToken = ''; /** @var array}>> */ - protected array $issue_baseline = []; + private array $issue_baseline = []; /** * This should actually be a private property on `parent` diff --git a/src/Psalm/Internal/PhpVisitor/AssignmentMapVisitor.php b/src/Psalm/Internal/PhpVisitor/AssignmentMapVisitor.php index a1ea12f334e..de750effdf5 100644 --- a/src/Psalm/Internal/PhpVisitor/AssignmentMapVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/AssignmentMapVisitor.php @@ -20,7 +20,7 @@ final class AssignmentMapVisitor extends PhpParser\NodeVisitorAbstract /** * @var array> */ - protected array $assignment_map = []; + private array $assignment_map = []; public function __construct(protected ?string $this_class_name) { diff --git a/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php b/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php index 9c1bfa9de3f..1a3a14fdd2c 100644 --- a/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php @@ -14,7 +14,7 @@ final class CheckTrivialExprVisitor extends PhpParser\NodeVisitorAbstract /** * @var array */ - protected array $non_trivial_expr = []; + private array $non_trivial_expr = []; private function checkNonTrivialExpr(PhpParser\Node\Expr $node): bool { diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php index d073445d4e1..e94a64ba10f 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php @@ -528,7 +528,7 @@ public static function parse( * 'psalm-property-read'|'property-write'|'psalm-property-write' $property_tag * @throws DocblockParseException */ - protected static function addMagicPropertyToInfo( + private static function addMagicPropertyToInfo( Doc $comment, ClassLikeDocblockComment $info, array $specials, diff --git a/src/Psalm/Internal/PhpVisitor/ShortClosureVisitor.php b/src/Psalm/Internal/PhpVisitor/ShortClosureVisitor.php index 18137b22723..c10bc26ead5 100644 --- a/src/Psalm/Internal/PhpVisitor/ShortClosureVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ShortClosureVisitor.php @@ -16,7 +16,7 @@ final class ShortClosureVisitor extends PhpParser\NodeVisitorAbstract /** * @var array */ - protected array $used_variables = []; + private array $used_variables = []; public function enterNode(PhpParser\Node $node): ?int { diff --git a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php index e62040ae3e9..455a22696df 100644 --- a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php +++ b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php @@ -202,7 +202,7 @@ private function resolveType(?Node $node): ?Node * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * @return Name Resolved name, or original name with attribute */ - protected function resolveName(Name $name, int $type): Name + private function resolveName(Name $name, int $type): Name { $resolvedName = $this->nameContext->getResolvedName($name, $type); if (null !== $resolvedName) { @@ -220,12 +220,12 @@ protected function resolveName(Name $name, int $type): Name return $name; } - protected function resolveClassName(Name $name): Name + private function resolveClassName(Name $name): Name { return $this->resolveName($name, Stmt\Use_::TYPE_NORMAL); } - protected function addNamespacedName(Stmt\Class_ $node): void + private function addNamespacedName(Stmt\Class_ $node): void { $node->setAttribute('namespacedName', Name::concat( $this->nameContext->getNamespace(), @@ -233,7 +233,7 @@ protected function addNamespacedName(Stmt\Class_ $node): void )); } - protected function resolveAttrGroups(Stmt\Class_ $node): void + private function resolveAttrGroups(Stmt\Class_ $node): void { foreach ($node->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { @@ -242,7 +242,7 @@ protected function resolveAttrGroups(Stmt\Class_ $node): void } } - protected function resolveTrait(Stmt\Trait_ $node): void + private function resolveTrait(Stmt\Trait_ $node): void { $resolvedName = Name::concat($this->nameContext->getNamespace(), (string) $node->name); diff --git a/src/Psalm/Internal/PluginManager/PluginList.php b/src/Psalm/Internal/PluginManager/PluginList.php index 89c41e7be3a..42ff53e13e6 100644 --- a/src/Psalm/Internal/PluginManager/PluginList.php +++ b/src/Psalm/Internal/PluginManager/PluginList.php @@ -16,7 +16,7 @@ /** * @internal */ -class PluginList +final class PluginList { /** @var ?array [pluginClass => packageName] */ private ?array $all_plugins = null; diff --git a/src/Psalm/Internal/PluginManager/PluginListFactory.php b/src/Psalm/Internal/PluginManager/PluginListFactory.php index c6daf1b634b..d64f4af373a 100644 --- a/src/Psalm/Internal/PluginManager/PluginListFactory.php +++ b/src/Psalm/Internal/PluginManager/PluginListFactory.php @@ -18,7 +18,7 @@ /** * @internal */ -class PluginListFactory +final class PluginListFactory { public function __construct(private readonly string $project_root, private readonly string $psalm_root) { diff --git a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php index c35c5e38238..2dfc5736357 100644 --- a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php @@ -26,7 +26,7 @@ /** * @internal */ -class ClassLikeStorageCacheProvider +final class ClassLikeStorageCacheProvider { private readonly Cache $cache; diff --git a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php index 793e916989a..6a69e2018f3 100644 --- a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php @@ -28,7 +28,7 @@ * @psalm-import-type FileMapType from Analyzer * @internal */ -class FileReferenceCacheProvider +final class FileReferenceCacheProvider { private const REFERENCE_CACHE_NAME = 'references'; private const CLASSLIKE_FILE_CACHE_NAME = 'classlike_files'; @@ -50,7 +50,7 @@ class FileReferenceCacheProvider private const FILE_MISSING_MEMBER_CACHE_NAME = 'file_missing_member'; private const UNKNOWN_MEMBER_CACHE_NAME = 'unknown_member_references'; private const METHOD_PARAM_USE_CACHE_NAME = 'method_param_uses'; - protected Cache $cache; + private readonly Cache $cache; public function __construct(protected Config $config) { diff --git a/src/Psalm/Internal/Provider/FileStorageCacheProvider.php b/src/Psalm/Internal/Provider/FileStorageCacheProvider.php index 8419afd80fb..411d79ec9b4 100644 --- a/src/Psalm/Internal/Provider/FileStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileStorageCacheProvider.php @@ -25,7 +25,7 @@ /** * @internal */ -class FileStorageCacheProvider +final class FileStorageCacheProvider { private string $modified_timestamps = ''; @@ -73,7 +73,7 @@ public function writeToCache(FileStorage $storage, string $file_contents): void /** * @param lowercase-string $file_path */ - protected function storeInCache(string $file_path, FileStorage $storage): void + private function storeInCache(string $file_path, FileStorage $storage): void { $cache_location = $this->getCacheLocationForPath($file_path, true); $this->cache->saveItem($cache_location, $storage); @@ -119,7 +119,7 @@ private function getCacheHash(string $_unused_file_path, string $file_contents): /** * @param lowercase-string $file_path */ - protected function loadFromCache(string $file_path): ?FileStorage + private function loadFromCache(string $file_path): ?FileStorage { $storage = $this->cache->getItem($this->getCacheLocationForPath($file_path)); if ($storage instanceof FileStorage) { diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index 6c74fc06b22..36598b619d3 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -38,7 +38,7 @@ /** * @internal */ -class ParserCacheProvider +final class ParserCacheProvider { private const FILE_HASHES = 'file_hashes_json'; private const PARSER_CACHE_DIRECTORY = 'php-parser'; @@ -51,14 +51,14 @@ class ParserCacheProvider * * @var array|null */ - protected ?array $existing_file_content_hashes = null; + private ?array $existing_file_content_hashes = null; /** * A map of recently-added filename hashes to contents hashes * * @var array */ - protected array $new_file_content_hashes = []; + private array $new_file_content_hashes = []; public function __construct(Config $config, private readonly bool $use_file_cache = true) { diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index 125e6f9c725..26b02f25ca4 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -22,7 +22,7 @@ * * @internal */ -class ProjectCacheProvider +final class ProjectCacheProvider { private const GOOD_RUN_NAME = 'good_run'; private const COMPOSER_LOCK_HASH = 'composer_lock_hash'; @@ -116,7 +116,7 @@ public function updateComposerLockHash(): void file_put_contents($lock_hash_location, $this->composer_lock_hash); } - protected function getComposerLockHash(): string + private function getComposerLockHash(): string { if ($this->composer_lock_hash === null) { $cache_directory = Config::getInstance()->getCacheDirectory(); diff --git a/src/Psalm/Internal/Scanner/FileScanner.php b/src/Psalm/Internal/Scanner/FileScanner.php index d8ba100c47f..d7bf827fecb 100644 --- a/src/Psalm/Internal/Scanner/FileScanner.php +++ b/src/Psalm/Internal/Scanner/FileScanner.php @@ -18,7 +18,7 @@ * @internal * @psalm-consistent-constructor */ -class FileScanner implements FileSource +final class FileScanner implements FileSource { public function __construct(public string $file_path, public string $file_name, public bool $will_analyze) { diff --git a/src/Psalm/Issue/InvalidInterfaceImplementation.php b/src/Psalm/Issue/InvalidInterfaceImplementation.php index 1acfa745e1f..ddaa2a62c3d 100644 --- a/src/Psalm/Issue/InvalidInterfaceImplementation.php +++ b/src/Psalm/Issue/InvalidInterfaceImplementation.php @@ -4,7 +4,7 @@ namespace Psalm\Issue; -class InvalidInterfaceImplementation extends ClassIssue +final class InvalidInterfaceImplementation extends ClassIssue { final public const ERROR_LEVEL = -1; final public const SHORTCODE = 317; diff --git a/src/Psalm/Issue/PrivateFinalMethod.php b/src/Psalm/Issue/PrivateFinalMethod.php index 1df8c8421a0..889fbd4ef2a 100644 --- a/src/Psalm/Issue/PrivateFinalMethod.php +++ b/src/Psalm/Issue/PrivateFinalMethod.php @@ -4,7 +4,7 @@ namespace Psalm\Issue; -class PrivateFinalMethod extends MethodIssue +final class PrivateFinalMethod extends MethodIssue { final public const ERROR_LEVEL = 2; final public const SHORTCODE = 320; diff --git a/src/Psalm/Issue/RiskyCast.php b/src/Psalm/Issue/RiskyCast.php index 6f58ecdcf2e..f4cb5da41b5 100644 --- a/src/Psalm/Issue/RiskyCast.php +++ b/src/Psalm/Issue/RiskyCast.php @@ -4,7 +4,7 @@ namespace Psalm\Issue; -class RiskyCast extends CodeIssue +final class RiskyCast extends CodeIssue { final public const ERROR_LEVEL = 3; final public const SHORTCODE = 313; diff --git a/src/Psalm/Issue/UnusedBaselineEntry.php b/src/Psalm/Issue/UnusedBaselineEntry.php index 266ec1e8b4c..dd74a2239d1 100644 --- a/src/Psalm/Issue/UnusedBaselineEntry.php +++ b/src/Psalm/Issue/UnusedBaselineEntry.php @@ -4,7 +4,7 @@ namespace Psalm\Issue; -class UnusedBaselineEntry extends ClassIssue +final class UnusedBaselineEntry extends ClassIssue { final public const ERROR_LEVEL = -1; final public const SHORTCODE = 316; diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 8008513c792..e2834f1eb37 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -86,39 +86,39 @@ final class IssueBuffer /** * @var array> */ - protected static array $issues_data = []; + private static array $issues_data = []; /** * @var array */ - protected static array $console_issues = []; + private static array $console_issues = []; /** * @var array */ - protected static array $fixable_issue_counts = []; + private static array $fixable_issue_counts = []; - protected static int $error_count = 0; + private static int $error_count = 0; /** * @var array */ - protected static array $emitted = []; + private static array $emitted = []; - protected static int $recording_level = 0; + private static int $recording_level = 0; /** @var array> */ - protected static array $recorded_issues = []; + private static array $recorded_issues = []; /** * @var array> */ - protected static array $unused_suppressions = []; + private static array $unused_suppressions = []; /** * @var array> */ - protected static array $used_suppressions = []; + private static array $used_suppressions = []; /** @var array */ private static array $server = []; @@ -887,7 +887,7 @@ public static function getOutput( return $output->create(); } - protected static function alreadyEmitted(string $message): bool + private static function alreadyEmitted(string $message): bool { $sham = sha1($message); diff --git a/src/Psalm/Progress/DefaultProgress.php b/src/Psalm/Progress/DefaultProgress.php index 57024cbf72f..59381fa938e 100644 --- a/src/Psalm/Progress/DefaultProgress.php +++ b/src/Psalm/Progress/DefaultProgress.php @@ -9,7 +9,7 @@ use function str_repeat; use function strlen; -class DefaultProgress extends LongProgress +final class DefaultProgress extends LongProgress { private const TOO_MANY_FILES = 1_500; diff --git a/src/Psalm/Report/CodeClimateReport.php b/src/Psalm/Report/CodeClimateReport.php index 9fd215026f0..61027d6371b 100644 --- a/src/Psalm/Report/CodeClimateReport.php +++ b/src/Psalm/Report/CodeClimateReport.php @@ -39,7 +39,7 @@ public function create(): string * convert our own severity to CodeClimate format * Values can be : info, minor, major, critical, or blocker */ - protected function convertSeverity(string $input): string + private function convertSeverity(string $input): string { if (Config::REPORT_INFO === $input) { return 'info'; @@ -58,7 +58,7 @@ protected function convertSeverity(string $input): string /** * calculate a unique fingerprint for a given issue */ - protected function calculateFingerprint(IssueData $issue): string + private function calculateFingerprint(IssueData $issue): string { return md5($issue->type.$issue->message.$issue->file_name.$issue->from.$issue->to); } diff --git a/src/Psalm/SourceControl/Git/CommitInfo.php b/src/Psalm/SourceControl/Git/CommitInfo.php index d10bbb41c0b..e0e70bad284 100644 --- a/src/Psalm/SourceControl/Git/CommitInfo.php +++ b/src/Psalm/SourceControl/Git/CommitInfo.php @@ -14,37 +14,37 @@ final class CommitInfo /** * Commit ID. */ - protected ?string $id = null; + private ?string $id = null; /** * Author name. */ - protected ?string $author_name = null; + private ?string $author_name = null; /** * Author email. */ - protected ?string $author_email = null; + private ?string $author_email = null; /** * Committer name. */ - protected ?string $committer_name = null; + private ?string $committer_name = null; /** * Committer email. */ - protected ?string $committer_email = null; + private ?string $committer_email = null; /** * Commit message. */ - protected ?string $message = null; + private ?string $message = null; /** * Commit message. */ - protected ?int $date = null; + private ?int $date = null; public function toArray(): array { diff --git a/src/Psalm/SourceControl/Git/RemoteInfo.php b/src/Psalm/SourceControl/Git/RemoteInfo.php index 91bf9a9b44a..ebb551b2186 100644 --- a/src/Psalm/SourceControl/Git/RemoteInfo.php +++ b/src/Psalm/SourceControl/Git/RemoteInfo.php @@ -14,12 +14,12 @@ final class RemoteInfo /** * Remote name. */ - protected ?string $name = null; + private ?string $name = null; /** * Remote URL. */ - protected ?string $url = null; + private ?string $url = null; public function toArray(): array {