From a52f35e5e1d6faf83c4de47fa28f04effb1ffe93 Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Fri, 16 Dec 2022 12:58:47 -0600 Subject: [PATCH 1/2] Even more property typehints --- phpcs.xml | 57 ++++++++----------- src/Psalm/CodeLocation.php | 9 +-- src/Psalm/Config.php | 5 +- .../Internal/Fork/ForkProcessErrorMessage.php | 2 +- .../Report/ByIssueLevelAndTypeReport.php | 3 +- src/Psalm/Report/ConsoleReport.php | 3 +- src/Psalm/Type/MutableUnion.php | 18 +++--- src/Psalm/Type/Union.php | 18 +++--- tests/CodebaseTest.php | 3 +- tests/Config/ConfigFileTest.php | 3 +- tests/Config/ConfigTest.php | 6 +- .../Plugin/FileTypeSelfRegisteringPlugin.php | 7 +-- tests/Config/PluginTest.php | 6 +- tests/DocumentationTest.php | 9 +-- tests/EndToEnd/PsalmEndToEndTest.php | 3 +- tests/EndToEnd/PsalmRunnerTrait.php | 6 +- .../ClassConstantMoveTest.php | 3 +- tests/FileManipulation/ClassMoveTest.php | 3 +- .../FileManipulationTestCase.php | 3 +- tests/FileManipulation/MethodMoveTest.php | 3 +- tests/FileManipulation/NamespaceMoveTest.php | 3 +- tests/FileManipulation/PropertyMoveTest.php | 3 +- tests/FileReferenceTest.php | 3 +- tests/FunctionLikeDocblockParserTest.php | 6 +- .../ClassConstantByWildcardResolverTest.php | 5 +- tests/Internal/Codebase/ClassLikesTest.php | 12 +--- .../Codebase/InternalCallMapHandlerTest.php | 16 ++---- .../ClassLikeStorageInstanceCacheProvider.php | 2 +- .../FakeFileReferenceCacheProvider.php | 52 ++++++----------- .../FileStorageInstanceCacheProvider.php | 2 +- .../Provider/ParserInstanceCacheProvider.php | 8 +-- .../Provider/ProjectCacheProvider.php | 5 +- tests/ProjectCheckerTest.php | 9 +-- tests/PsalmPluginTest.php | 3 +- tests/StubTest.php | 3 +- tests/TestCase.php | 12 ++-- tests/TestConfig.php | 3 +- tests/TypeReconciliation/ReconcilerTest.php | 6 +- tests/UnusedCodeTest.php | 3 +- tests/UnusedVariableTest.php | 3 +- 40 files changed, 114 insertions(+), 215 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index b539ffc6481..58405663775 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -10,7 +10,7 @@ * Configuration * ************************************************************************************************************** --> - + @@ -86,10 +86,10 @@ --> - - - - + + + + @@ -113,8 +113,8 @@ --> - - + + @@ -128,21 +128,21 @@ --> - - - - + + + + - - - + + + - - + + - + - + @@ -162,7 +162,7 @@ --> - + @@ -228,17 +228,6 @@ --> - - - - - - - - - src/Psalm/Storage/Assertion/HasArrayKey\.php - src/Psalm/Storage/Assertion/IsNotCountable\.php - src/Psalm/Storage/Assertion/NonEmptyCountable\.php + + bin/* + src/Psalm/Internal/* + tests/* diff --git a/src/Psalm/CodeLocation.php b/src/Psalm/CodeLocation.php index 1b131a1ac1e..c962cdb2804 100644 --- a/src/Psalm/CodeLocation.php +++ b/src/Psalm/CodeLocation.php @@ -74,20 +74,17 @@ class CodeLocation private string $snippet = ''; - /** @var null|string */ - private $text; + private ?string $text = null; /** @var int|null */ public $docblock_start; - /** @var int|null */ - private $docblock_start_line_number; + private ?int $docblock_start_line_number = null; /** @var int|null */ protected $docblock_line_number; - /** @var null|int */ - private $regex_type; + private ?int $regex_type = null; private bool $have_recalculated = false; diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 501ec81a0aa..45431cc0feb 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -559,10 +559,7 @@ class Config */ public $debug_emitted_issues = false; - /** - * @var bool - */ - private $report_info = true; + private bool $report_info = true; /** * @var EventDispatcher diff --git a/src/Psalm/Internal/Fork/ForkProcessErrorMessage.php b/src/Psalm/Internal/Fork/ForkProcessErrorMessage.php index cb75509e6cb..6bf9acb2c12 100644 --- a/src/Psalm/Internal/Fork/ForkProcessErrorMessage.php +++ b/src/Psalm/Internal/Fork/ForkProcessErrorMessage.php @@ -11,7 +11,7 @@ class ForkProcessErrorMessage implements ForkMessage { use ImmutableNonCloneableTrait; - + public string $message; public function __construct(string $message) diff --git a/src/Psalm/Report/ByIssueLevelAndTypeReport.php b/src/Psalm/Report/ByIssueLevelAndTypeReport.php index b2d43542636..1ade682eee4 100644 --- a/src/Psalm/Report/ByIssueLevelAndTypeReport.php +++ b/src/Psalm/Report/ByIssueLevelAndTypeReport.php @@ -17,8 +17,7 @@ final class ByIssueLevelAndTypeReport extends Report { - /** @var string|null */ - private $link_format; + private ?string $link_format = null; public function create(): string { diff --git a/src/Psalm/Report/ConsoleReport.php b/src/Psalm/Report/ConsoleReport.php index f968326f1a0..539c3db8766 100644 --- a/src/Psalm/Report/ConsoleReport.php +++ b/src/Psalm/Report/ConsoleReport.php @@ -16,8 +16,7 @@ final class ConsoleReport extends Report { - /** @var string|null */ - private $link_format; + private ?string $link_format = null; public function create(): string { diff --git a/src/Psalm/Type/MutableUnion.php b/src/Psalm/Type/MutableUnion.php index 7f58f011d33..a1a08cd7ee0 100644 --- a/src/Psalm/Type/MutableUnion.php +++ b/src/Psalm/Type/MutableUnion.php @@ -36,7 +36,7 @@ final class MutableUnion implements TypeNode, Stringable /** * @var non-empty-array */ - private $types; + private array $types; /** * Whether the type originated in a docblock @@ -158,22 +158,22 @@ final class MutableUnion implements TypeNode, Stringable /** * @var array */ - private $literal_string_types = []; + private array $literal_string_types = []; /** * @var array */ - private $typed_class_strings = []; + private array $typed_class_strings = []; /** * @var array */ - private $literal_int_types = []; + private array $literal_int_types = []; /** * @var array */ - private $literal_float_types = []; + private array $literal_float_types = []; /** * True if the type was passed or returned by reference, or if the type refers to an object's @@ -201,17 +201,13 @@ final class MutableUnion implements TypeNode, Stringable /** * This is a cache of getId on non-exact mode - * - * @var null|string */ - private $id; + private ?string $id = null; /** * This is a cache of getId on exact mode - * - * @var null|string */ - private $exact_id; + private ?string $exact_id = null; /** diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 28feb978ac1..03dea469914 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -49,7 +49,7 @@ final class Union implements TypeNode, Stringable * @psalm-readonly * @var non-empty-array */ - private $types; + private array $types; /** * Whether the type originated in a docblock @@ -170,22 +170,22 @@ final class Union implements TypeNode, Stringable /** * @var array */ - private $literal_string_types = []; + private array $literal_string_types = []; /** * @var array */ - private $typed_class_strings = []; + private array $typed_class_strings = []; /** * @var array */ - private $literal_int_types = []; + private array $literal_int_types = []; /** * @var array */ - private $literal_float_types = []; + private array $literal_float_types = []; /** * True if the type was passed or returned by reference, or if the type refers to an object's @@ -213,17 +213,13 @@ final class Union implements TypeNode, Stringable /** * This is a cache of getId on non-exact mode - * - * @var null|string */ - private $id; + private ?string $id = null; /** * This is a cache of getId on exact mode - * - * @var null|string */ - private $exact_id; + private ?string $exact_id; /** diff --git a/tests/CodebaseTest.php b/tests/CodebaseTest.php index 8bb104e3a20..8d9e4823a22 100644 --- a/tests/CodebaseTest.php +++ b/tests/CodebaseTest.php @@ -24,8 +24,7 @@ class CodebaseTest extends TestCase { - /** @var Codebase */ - private $codebase; + private Codebase $codebase; public function setUp(): void { diff --git a/tests/Config/ConfigFileTest.php b/tests/Config/ConfigFileTest.php index 32d1fc570ff..0b5e5ac321f 100644 --- a/tests/Config/ConfigFileTest.php +++ b/tests/Config/ConfigFileTest.php @@ -21,8 +21,7 @@ /** @group PluginManager */ class ConfigFileTest extends TestCase { - /** @var string */ - private $file_path; + private string $file_path; public function setUp(): void { diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 321bb8c48d2..65d3a3845f5 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -43,11 +43,9 @@ class ConfigTest extends TestCase { - /** @var TestConfig */ - protected static $config; + protected static TestConfig $config; - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; /** @var callable(int, string, string=, int=, array=):bool|null */ protected $original_error_handler = null; diff --git a/tests/Config/Plugin/FileTypeSelfRegisteringPlugin.php b/tests/Config/Plugin/FileTypeSelfRegisteringPlugin.php index 666e950e833..2996de3244d 100644 --- a/tests/Config/Plugin/FileTypeSelfRegisteringPlugin.php +++ b/tests/Config/Plugin/FileTypeSelfRegisteringPlugin.php @@ -18,12 +18,9 @@ class FileTypeSelfRegisteringPlugin implements PluginFileExtensionsInterface /** * @var array */ - public static $names = []; + public static array $names = []; - /** - * @var int - */ - public static $flags = 0; + public static int $flags = 0; public function processFileExtensions(FileExtensionsInterface $fileExtensions, ?SimpleXMLElement $config = null): void { diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 1fd197ec02a..62319390e9b 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -39,8 +39,7 @@ class PluginTest extends TestCase { - /** @var TestConfig */ - protected static $config; + protected static TestConfig $config; public static function setUpBeforeClass(): void { @@ -873,8 +872,7 @@ public function testAfterEveryFunctionPluginIsCalledInAllCases(): void [$this->equalTo('a')] ); $plugin = new class($mock) implements AfterEveryFunctionCallAnalysisInterface { - /** @var MockObject */ - private static $m; + private static MockObject $m; public function __construct(MockObject $m) { diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index 99616bbac55..bb67c71bb65 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -83,11 +83,9 @@ class DocumentationTest extends TestCase '@psalm-stub-override', ]; - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; - /** @var string */ - private static $docContents = ''; + private static string $docContents = ''; /** * @return array> @@ -389,8 +387,7 @@ public function conciseExpected(Constraint $inner): Constraint { return new class ($inner) extends Constraint { - /** @var Constraint */ - private $inner; + private Constraint $inner; public function __construct(Constraint $inner) { diff --git a/tests/EndToEnd/PsalmEndToEndTest.php b/tests/EndToEnd/PsalmEndToEndTest.php index e8e9ddb1ee5..8933d0d9ae1 100644 --- a/tests/EndToEnd/PsalmEndToEndTest.php +++ b/tests/EndToEnd/PsalmEndToEndTest.php @@ -35,8 +35,7 @@ class PsalmEndToEndTest extends TestCase { use PsalmRunnerTrait; - /** @var string */ - private static $tmpDir; + private static string $tmpDir; public static function setUpBeforeClass(): void { diff --git a/tests/EndToEnd/PsalmRunnerTrait.php b/tests/EndToEnd/PsalmRunnerTrait.php index 309de6a6e66..14361055364 100644 --- a/tests/EndToEnd/PsalmRunnerTrait.php +++ b/tests/EndToEnd/PsalmRunnerTrait.php @@ -8,11 +8,9 @@ trait PsalmRunnerTrait { - /** @var string */ - private $psalm = __DIR__ . '/../../psalm'; + private string $psalm = __DIR__ . '/../../psalm'; - /** @var string */ - private $psalter = __DIR__ . '/../../psalter'; + private string $psalter = __DIR__ . '/../../psalter'; /** * @param list $args diff --git a/tests/FileManipulation/ClassConstantMoveTest.php b/tests/FileManipulation/ClassConstantMoveTest.php index 767d0d67d7e..4c4e7152a63 100644 --- a/tests/FileManipulation/ClassConstantMoveTest.php +++ b/tests/FileManipulation/ClassConstantMoveTest.php @@ -15,8 +15,7 @@ class ClassConstantMoveTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FileManipulation/ClassMoveTest.php b/tests/FileManipulation/ClassMoveTest.php index 6dd79265e84..614d4abdb12 100644 --- a/tests/FileManipulation/ClassMoveTest.php +++ b/tests/FileManipulation/ClassMoveTest.php @@ -15,8 +15,7 @@ class ClassMoveTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FileManipulation/FileManipulationTestCase.php b/tests/FileManipulation/FileManipulationTestCase.php index 627b31ebb9b..b0f24142020 100644 --- a/tests/FileManipulation/FileManipulationTestCase.php +++ b/tests/FileManipulation/FileManipulationTestCase.php @@ -15,8 +15,7 @@ abstract class FileManipulationTestCase extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FileManipulation/MethodMoveTest.php b/tests/FileManipulation/MethodMoveTest.php index 0542c6ed538..aacef2b9c9a 100644 --- a/tests/FileManipulation/MethodMoveTest.php +++ b/tests/FileManipulation/MethodMoveTest.php @@ -15,8 +15,7 @@ class MethodMoveTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FileManipulation/NamespaceMoveTest.php b/tests/FileManipulation/NamespaceMoveTest.php index f72feb277f7..9853909285c 100644 --- a/tests/FileManipulation/NamespaceMoveTest.php +++ b/tests/FileManipulation/NamespaceMoveTest.php @@ -15,8 +15,7 @@ class NamespaceMoveTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FileManipulation/PropertyMoveTest.php b/tests/FileManipulation/PropertyMoveTest.php index b313ada0269..df2ec1f01ac 100644 --- a/tests/FileManipulation/PropertyMoveTest.php +++ b/tests/FileManipulation/PropertyMoveTest.php @@ -15,8 +15,7 @@ class PropertyMoveTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FileReferenceTest.php b/tests/FileReferenceTest.php index 42d7d959780..e8661e2328e 100644 --- a/tests/FileReferenceTest.php +++ b/tests/FileReferenceTest.php @@ -15,8 +15,7 @@ class FileReferenceTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/FunctionLikeDocblockParserTest.php b/tests/FunctionLikeDocblockParserTest.php index b525edac224..e8e2e4365d2 100644 --- a/tests/FunctionLikeDocblockParserTest.php +++ b/tests/FunctionLikeDocblockParserTest.php @@ -17,11 +17,9 @@ class FunctionLikeDocblockParserTest extends BaseTestCase { - /** @var string */ - public $test_cased_function_id = 'hello_world'; + public string $test_cased_function_id = 'hello_world'; - /** @var CodeLocation */ - public $test_code_location; + public CodeLocation $test_code_location; public function setUp(): void { diff --git a/tests/Internal/Codebase/ClassConstantByWildcardResolverTest.php b/tests/Internal/Codebase/ClassConstantByWildcardResolverTest.php index 8000ec8b5b9..8519a296277 100644 --- a/tests/Internal/Codebase/ClassConstantByWildcardResolverTest.php +++ b/tests/Internal/Codebase/ClassConstantByWildcardResolverTest.php @@ -10,10 +10,7 @@ final class ClassConstantByWildcardResolverTest extends TestCase { - /** - * @var ClassConstantByWildcardResolver - */ - private $resolver; + private ClassConstantByWildcardResolver $resolver; public function setUp(): void { diff --git a/tests/Internal/Codebase/ClassLikesTest.php b/tests/Internal/Codebase/ClassLikesTest.php index 8168d17a875..61a6e28378d 100644 --- a/tests/Internal/Codebase/ClassLikesTest.php +++ b/tests/Internal/Codebase/ClassLikesTest.php @@ -11,15 +11,9 @@ final class ClassLikesTest extends TestCase { - /** - * @var ClassLikes - */ - private $classlikes; - - /** - * @var ClassLikeStorageProvider - */ - private $storage_provider; + private ClassLikes $classlikes; + + private ClassLikeStorageProvider $storage_provider; public function setUp(): void { diff --git a/tests/Internal/Codebase/InternalCallMapHandlerTest.php b/tests/Internal/Codebase/InternalCallMapHandlerTest.php index 0ae27d7202b..fa613deee99 100644 --- a/tests/Internal/Codebase/InternalCallMapHandlerTest.php +++ b/tests/Internal/Codebase/InternalCallMapHandlerTest.php @@ -52,7 +52,7 @@ class InternalCallMapHandlerTest extends TestCase * * @var array> */ - private static $ignoredFunctions = [ + private static array $ignoredFunctions = [ 'apcu_entry', 'argumentcounterror::__construct', 'arithmeticerror::__construct', @@ -903,7 +903,7 @@ class InternalCallMapHandlerTest extends TestCase * * @var array> */ - private static $ignoredReturnTypeOnlyFunctions = [ + private static array $ignoredReturnTypeOnlyFunctions = [ 'appenditerator::getinneriterator' => ['8.1', '8.2'], 'appenditerator::getiteratorindex' => ['8.1', '8.2'], 'arrayiterator::key' => ['8.1', '8.2'], @@ -1218,7 +1218,7 @@ class InternalCallMapHandlerTest extends TestCase * * @var array> */ - private static $ignoredUnreflectableFunctions = [ + private static array $ignoredUnreflectableFunctions = [ 'closure::__invoke', 'curlfile::__wakeup', 'domimplementation::__construct', @@ -1283,10 +1283,7 @@ class InternalCallMapHandlerTest extends TestCase 'weakmap::valid', ]; - /** - * @var Codebase - */ - private static $codebase; + private static Codebase $codebase; public static function setUpBeforeClass(): void { @@ -1314,11 +1311,6 @@ public function testIgnoresAreSortedAndUnique(): void } } - public static function tearDownAfterClass(): void - { - self::$codebase = null; - } - /** * @covers \Psalm\Internal\Codebase\InternalCallMapHandler::getCallMap */ diff --git a/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php b/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php index d68083af077..5af1cb945b1 100644 --- a/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php +++ b/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php @@ -11,7 +11,7 @@ class ClassLikeStorageInstanceCacheProvider extends ClassLikeStorageCacheProvider { /** @var array */ - private $cache = []; + private array $cache = []; public function __construct() { diff --git a/tests/Internal/Provider/FakeFileReferenceCacheProvider.php b/tests/Internal/Provider/FakeFileReferenceCacheProvider.php index 8e3c17ef2e6..e3893528d73 100644 --- a/tests/Internal/Provider/FakeFileReferenceCacheProvider.php +++ b/tests/Internal/Provider/FakeFileReferenceCacheProvider.php @@ -11,56 +11,40 @@ */ class FakeFileReferenceCacheProvider extends FileReferenceCacheProvider { - /** @var ?array */ - private $cached_file_references; + private ?array $cached_file_references = null; - /** @var ?array */ - private $cached_classlike_files; + private ?array $cached_classlike_files = null; - /** @var ?array */ - private $cached_method_class_references; + private ?array $cached_method_class_references = null; - /** @var ?array */ - private $cached_nonmethod_class_references; + private ?array $cached_nonmethod_class_references = null; - /** @var ?array */ - private $cached_method_member_references; + private ?array $cached_method_member_references = null; - /** @var ?array */ - private $cached_method_dependencies; + private ?array $cached_method_dependencies = null; - /** @var ?array */ - private $cached_method_property_references; + private ?array $cached_method_property_references = null; - /** @var ?array */ - private $cached_method_method_return_references; + private ?array $cached_method_method_return_references = null; - /** @var ?array */ - private $cached_file_member_references; + private ?array $cached_file_member_references = null; - /** @var ?array */ - private $cached_file_property_references; + private ?array $cached_file_property_references = null; - /** @var ?array */ - private $cached_file_method_return_references; + private ?array $cached_file_method_return_references = null; - /** @var ?array */ - private $cached_method_missing_member_references; + private ?array $cached_method_missing_member_references = null; - /** @var ?array */ - private $cached_file_missing_member_references; + private ?array $cached_file_missing_member_references = null; - /** @var ?array */ - private $cached_unknown_member_references; + private ?array $cached_unknown_member_references = null; - /** @var ?array */ - private $cached_method_param_uses; + private ?array $cached_method_param_uses = null; - /** @var ?array */ - private $cached_issues; + private ?array $cached_issues = null; /** @var array> */ - private $cached_correct_methods = []; + private array $cached_correct_methods = []; /** * @var array< @@ -72,7 +56,7 @@ class FakeFileReferenceCacheProvider extends FileReferenceCacheProvider * } * > */ - private $cached_file_maps = []; + private array $cached_file_maps = []; public function __construct() { diff --git a/tests/Internal/Provider/FileStorageInstanceCacheProvider.php b/tests/Internal/Provider/FileStorageInstanceCacheProvider.php index e496525c023..7889520c374 100644 --- a/tests/Internal/Provider/FileStorageInstanceCacheProvider.php +++ b/tests/Internal/Provider/FileStorageInstanceCacheProvider.php @@ -10,7 +10,7 @@ class FileStorageInstanceCacheProvider extends FileStorageCacheProvider { /** @var array */ - private $cache = []; + private array $cache = []; public function __construct() { diff --git a/tests/Internal/Provider/ParserInstanceCacheProvider.php b/tests/Internal/Provider/ParserInstanceCacheProvider.php index e0bc1ef5671..979e860ee4f 100644 --- a/tests/Internal/Provider/ParserInstanceCacheProvider.php +++ b/tests/Internal/Provider/ParserInstanceCacheProvider.php @@ -12,22 +12,22 @@ class ParserInstanceCacheProvider extends ParserCacheProvider /** * @var array */ - private $file_contents_cache = []; + private array $file_contents_cache = []; /** * @var array */ - private $file_content_hash = []; + private array $file_content_hash = []; /** * @var array> */ - private $statements_cache = []; + private array $statements_cache = []; /** * @var array */ - private $statements_cache_time = []; + private array $statements_cache_time = []; public function __construct() { diff --git a/tests/Internal/Provider/ProjectCacheProvider.php b/tests/Internal/Provider/ProjectCacheProvider.php index a991e3f38ef..de162b842d8 100644 --- a/tests/Internal/Provider/ProjectCacheProvider.php +++ b/tests/Internal/Provider/ProjectCacheProvider.php @@ -6,10 +6,7 @@ class ProjectCacheProvider extends PsalmProjectCacheProvider { - /** - * @var int - */ - private $last_run = 0; + private int $last_run = 0; public function __construct() { diff --git a/tests/ProjectCheckerTest.php b/tests/ProjectCheckerTest.php index c9fa676d355..6920e14b4f2 100644 --- a/tests/ProjectCheckerTest.php +++ b/tests/ProjectCheckerTest.php @@ -34,11 +34,9 @@ class ProjectCheckerTest extends TestCase { - /** @var TestConfig */ - protected static $config; + protected static TestConfig $config; - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; private const EXPECTED_OUTPUT = "Target PHP version: 8.1 (set by tests) Extensions enabled: dom, simplexml " . "(unsupported extensions: ctype, json, libxml, mbstring, tokenizer)\n" @@ -123,8 +121,7 @@ public function testCheck(): void public function testAfterCodebasePopulatedIsInvoked(): void { $hook = new class implements AfterCodebasePopulatedInterface { - /** @var bool */ - public static $called = false; + public static bool $called = false; /** * @return void diff --git a/tests/PsalmPluginTest.php b/tests/PsalmPluginTest.php index b6ad44b6048..4ba57ad3ecc 100644 --- a/tests/PsalmPluginTest.php +++ b/tests/PsalmPluginTest.php @@ -29,8 +29,7 @@ class PsalmPluginTest extends TestCase /** @var PluginListFactory&MockInterface */ private $plugin_list_factory; - /** @var Application */ - private $app; + private Application $app; public function setUp(): void { diff --git a/tests/StubTest.php b/tests/StubTest.php index 736943df32f..68c89282be8 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -27,8 +27,7 @@ class StubTest extends TestCase { - /** @var TestConfig */ - protected static $config; + protected static TestConfig $config; public static function setUpBeforeClass(): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index bca0036a1e8..d617b14aee3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,17 +30,13 @@ class TestCase extends BaseTestCase { - /** @var string */ - protected static $src_dir_path; + protected static string $src_dir_path; - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; - /** @var FakeFileProvider */ - protected $file_provider; + protected FakeFileProvider $file_provider; - /** @var Config */ - protected $testConfig; + protected Config $testConfig; public static function setUpBeforeClass(): void { diff --git a/tests/TestConfig.php b/tests/TestConfig.php index b442c22bd8b..518fa0f987c 100644 --- a/tests/TestConfig.php +++ b/tests/TestConfig.php @@ -13,8 +13,7 @@ class TestConfig extends Config { - /** @var ProjectFileFilter|null */ - private static $cached_project_files = null; + private static ?ProjectFileFilter $cached_project_files = null; public function __construct() { diff --git a/tests/TypeReconciliation/ReconcilerTest.php b/tests/TypeReconciliation/ReconcilerTest.php index 44363d6f20b..5ff1c2dfd51 100644 --- a/tests/TypeReconciliation/ReconcilerTest.php +++ b/tests/TypeReconciliation/ReconcilerTest.php @@ -37,11 +37,9 @@ class ReconcilerTest extends TestCase { - /** @var FileAnalyzer */ - protected $file_analyzer; + protected FileAnalyzer $file_analyzer; - /** @var StatementsAnalyzer */ - protected $statements_analyzer; + protected StatementsAnalyzer $statements_analyzer; public function setUp(): void { diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index bb061f0330a..bd862bd60ed 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -20,8 +20,7 @@ class UnusedCodeTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index 8ea31daa19d..497386d73b8 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -18,8 +18,7 @@ class UnusedVariableTest extends TestCase { - /** @var ProjectAnalyzer */ - protected $project_analyzer; + protected ProjectAnalyzer $project_analyzer; public function setUp(): void { From 9ce31a7709c35de136b754a373f20261255fff7e Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Fri, 16 Dec 2022 17:02:10 -0600 Subject: [PATCH 2/2] Re-add short closure sniff --- bin/generate_testsuites.php | 4 +--- bin/update-property-map.php | 8 ++----- phpcs.xml | 3 +++ .../Analyzer/Statements/Block/TryAnalyzer.php | 22 +++++++++---------- .../FunctionDocblockManipulator.php | 6 ++--- .../Report/ByIssueLevelAndTypeReport.php | 15 ++++++------- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/bin/generate_testsuites.php b/bin/generate_testsuites.php index 0f16d58d3be..195c418137d 100644 --- a/bin/generate_testsuites.php +++ b/bin/generate_testsuites.php @@ -30,9 +30,7 @@ // -- xkcd:221 $order = array_map( - function (): int { - return mt_rand(); - }, + fn(): int => mt_rand(), $files ); array_multisort($order, $files); diff --git a/bin/update-property-map.php b/bin/update-property-map.php index bed4923ba1d..b26a6e01dbe 100755 --- a/bin/update-property-map.php +++ b/bin/update-property-map.php @@ -100,9 +100,7 @@ function extractClassesFromStatements(array $statements): array $file, get_class($exception), $exception->getMessage(), - implode("\n", array_map(function (LibXMLError $error): string { - return $error->message; - }, libxml_get_errors())) + implode("\n", array_map(fn(LibXMLError $error): string => $error->message, libxml_get_errors())) ); libxml_clear_errors(); continue; @@ -159,9 +157,7 @@ function extractClassesFromStatements(array $statements): array function serializeArray(array $array, string $prefix): string { - uksort($array, function (string $first, string $second): int { - return strtolower($first) <=> strtolower($second); - }); + uksort($array, fn(string $first, string $second): int => strtolower($first) <=> strtolower($second)); $result = "[\n"; $localPrefix = $prefix . ' '; foreach ($array as $key => $value) { diff --git a/phpcs.xml b/phpcs.xml index 58405663775..33a83ea010f 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -228,6 +228,9 @@ --> + + +