Skip to content

Commit

Permalink
Require typed properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 17, 2021
1 parent 8a141ce commit acd6894
Show file tree
Hide file tree
Showing 81 changed files with 122 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lint:
--exclude tests/PHPStan/Rules/Properties/data/intersection-types.php \
--exclude tests/PHPStan/Rules/Classes/data/first-class-instantiation-callable.php \
--exclude tests/PHPStan/Rules/Classes/data/instantiation-callable.php \
src tests compiler/src
src tests

cs:
composer install --working-dir build-cs && php build-cs/vendor/bin/phpcs
Expand Down
3 changes: 3 additions & 0 deletions build/ignore-gte-php7.4-errors.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ parameters:
path: ../src/Reflection/Php/PhpClassReflectionExtension.php
- '#^Class PHPStan\\Rules\\RuleErrors\\RuleError(?:\d+) has an uninitialized property (?:\$message|\$line|\$identifier|\$tip|\$file|\$metadata)#'
- '#Extension has an uninitialized property (?:\$typeSpecifier|\$broker)#'
-
message: '#has an uninitialized property#'
path: ../tests
12 changes: 4 additions & 8 deletions compiler/src/Console/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@
final class CompileCommand extends Command
{

/** @var Filesystem */
private $filesystem;
private Filesystem $filesystem;

/** @var ProcessFactory */
private $processFactory;
private ProcessFactory $processFactory;

/** @var string */
private $dataDir;
private string $dataDir;

/** @var string */
private $buildDir;
private string $buildDir;

public function __construct(
Filesystem $filesystem,
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/Filesystem/SymfonyFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
final class SymfonyFilesystem implements Filesystem
{

/** @var \Symfony\Component\Filesystem\Filesystem */
private $filesystem;
private \Symfony\Component\Filesystem\Filesystem $filesystem;

public function __construct(\Symfony\Component\Filesystem\Filesystem $filesystem)
{
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/Process/DefaultProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
final class DefaultProcessFactory implements ProcessFactory
{

/** @var OutputInterface */
private $output;
private OutputInterface $output;

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/Process/SymfonyProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class SymfonyProcess implements Process
{

/** @var \Symfony\Component\Process\Process<string, string> */
private $process;
private \Symfony\Component\Process\Process $process;

/**
* @param string[] $command
Expand Down
3 changes: 3 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
<properties>
<property name="enableNativeTypeHint" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation">
<severity>10</severity>
Expand Down
29 changes: 10 additions & 19 deletions src/Command/FixerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,31 @@
class FixerApplication
{

/** @var FileMonitor */
private $fileMonitor;
private FileMonitor $fileMonitor;

/** @var ResultCacheManagerFactory */
private $resultCacheManagerFactory;
private ResultCacheManagerFactory $resultCacheManagerFactory;

/** @var ResultCacheClearer */
private $resultCacheClearer;
private ResultCacheClearer $resultCacheClearer;

/** @var IgnoredErrorHelper */
private $ignoredErrorHelper;
private IgnoredErrorHelper $ignoredErrorHelper;

/** @var CpuCoreCounter */
private $cpuCoreCounter;
private CpuCoreCounter $cpuCoreCounter;

/** @var Scheduler */
private $scheduler;
private Scheduler $scheduler;

/** @var string[] */
private $analysedPaths;
private array $analysedPaths;

/** @var (ExtendedPromiseInterface&CancellablePromiseInterface)|null */
private $processInProgress;

/** @var string */
private $currentWorkingDirectory;
private string $currentWorkingDirectory;

/** @var string */
private $fixerTmpDir;
private string $fixerTmpDir;

private int $maximumNumberOfProcesses;

/** @var string|null */
private $fixerSuggestionId;
private ?string $fixerSuggestionId = null;

/**
* @param string[] $analysedPaths
Expand Down
2 changes: 1 addition & 1 deletion src/Command/FixerWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FixerWorkerCommand extends Command
private const NAME = 'fixer:worker';

/** @var string[] */
private $composerAutoloaderProjectPaths;
private array $composerAutoloaderProjectPaths;

/**
* @param string[] $composerAutoloaderProjectPaths
Expand Down
7 changes: 3 additions & 4 deletions src/File/FileMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
class FileMonitor
{

/** @var FileFinder */
private $fileFinder;
private FileFinder $fileFinder;

/** @var array<string, string>|null */
private $fileHashes;
private ?array $fileHashes = null;

/** @var array<string>|null */
private $paths;
private ?array $paths = null;

public function __construct(FileFinder $fileFinder)
{
Expand Down
9 changes: 4 additions & 5 deletions src/File/FileMonitorResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ class FileMonitorResult
{

/** @var string[] */
private $newFiles;
private array $newFiles;

/** @var string[] */
private $changedFiles;
private array $changedFiles;

/** @var string[] */
private $deletedFiles;
private array $deletedFiles;

/** @var int */
private $totalFilesCount;
private int $totalFilesCount;

/**
* @param string[] $newFiles
Expand Down
9 changes: 3 additions & 6 deletions src/Process/ProcessPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
class ProcessPromise implements Runnable
{

/** @var LoopInterface */
private $loop;
private LoopInterface $loop;

/** @var string */
private $name;
private string $name;

/** @var string */
private $command;
private string $command;

private Deferred $deferred;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Whitespace/FileWhitespaceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function processNode(Node $node, Scope $scope): array
$visitor = new class () extends NodeVisitorAbstract {

/** @var Node[] */
private $lastNodes = [];
private array $lastNodes = [];

/**
* @return int|Node|null
Expand Down
3 changes: 1 addition & 2 deletions src/Testing/PHPStanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
abstract class PHPStanTestCase extends TestCase
{

/** @var bool */
public static $useStaticReflectionProvider = false;
public static bool $useStaticReflectionProvider = false;

/** @var array<string, Container> */
private static array $containers = [];
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
class AnalyserTraitsIntegrationTest extends PHPStanTestCase
{

/** @var FileHelper */
private $fileHelper;
private FileHelper $fileHelper;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Analyser/AnonymousClassNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
class AnonymousClassNameRule implements Rule
{

/** @var ReflectionProvider */
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;

public function __construct(ReflectionProvider $reflectionProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LegacyNodeScopeResolverTest extends TypeInferenceTestCase
{

/** @var Scope[][] */
private static $assertTypesCache = [];
private static array $assertTypesCache = [];

public function testClassMethodScope(): void
{
Expand Down
8 changes: 3 additions & 5 deletions tests/PHPStan/Analyser/TypeSpecifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ class TypeSpecifierTest extends PHPStanTestCase
private const SURE_NOT_TRUTHY = '~' . self::TRUTHY_TYPE_DESCRIPTION;

/** @var Standard () */
private $printer;
private Standard $printer;

/** @var TypeSpecifier */
private $typeSpecifier;
private TypeSpecifier $typeSpecifier;

/** @var Scope */
private $scope;
private Scope $scope;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Broker/BrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
class BrokerTest extends PHPStanTestCase
{

/** @var Broker */
private $broker;
private Broker $broker;

protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
class JunitErrorFormatterTest extends ErrorFormatterTestCase
{

/** @var JunitErrorFormatter */
private $formatter;
private JunitErrorFormatter $formatter;

public function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Process/Runnable/RunnableQueueLoggerStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RunnableQueueLoggerStub implements RunnableQueueLogger
{

/** @var string[] */
private $messages = [];
private array $messages = [];

/**
* @return string[]
Expand Down
6 changes: 2 additions & 4 deletions tests/PHPStan/Process/Runnable/RunnableStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
class RunnableStub implements Runnable
{

/** @var string */
private $name;
private string $name;

/** @var Deferred */
private $deferred;
private Deferred $deferred;

public function __construct(string $name)
{
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Rules/Arrays/IterableInForeachRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
class IterableInForeachRuleTest extends RuleTestCase
{

/** @var bool */
private $checkExplicitMixed = false;
private bool $checkExplicitMixed = false;

protected function getRule(): Rule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
class NonexistentOffsetInArrayDimFetchRuleTest extends RuleTestCase
{

/** @var bool */
private $checkExplicitMixed = false;
private bool $checkExplicitMixed = false;

protected function getRule(): Rule
{
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Rules/Arrays/OffsetAccessAssignOpRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
class OffsetAccessAssignOpRuleTest extends RuleTestCase
{

/** @var bool */
private $checkUnions;
private bool $checkUnions;

protected function getRule(): Rule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
class OffsetAccessAssignmentRuleTest extends RuleTestCase
{

/** @var bool */
private $checkUnionTypes;
private bool $checkUnionTypes;

protected function getRule(): Rule
{
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Rules/Cast/UnsetCastRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
class UnsetCastRuleTest extends RuleTestCase
{

/** @var int */
private $phpVersion;
private int $phpVersion;

protected function getRule(): Rule
{
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
class ClassConstantRuleTest extends RuleTestCase
{

/** @var int */
private $phpVersion;
private int $phpVersion;

protected function getRule(): Rule
{
Expand Down
6 changes: 2 additions & 4 deletions tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
class ImpossibleInstanceOfRuleTest extends RuleTestCase
{

/** @var bool */
private $checkAlwaysTrueInstanceOf;
private bool $checkAlwaysTrueInstanceOf;

/** @var bool */
private $treatPhpDocTypesAsCertain;
private bool $treatPhpDocTypesAsCertain;

protected function getRule(): Rule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
class InvalidPromotedPropertiesRuleTest extends RuleTestCase
{

/** @var int */
private $phpVersion;
private int $phpVersion;

protected function getRule(): Rule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
class BooleanAndConstantConditionRuleTest extends RuleTestCase
{

/** @var bool */
private $treatPhpDocTypesAsCertain;
private bool $treatPhpDocTypesAsCertain;

protected function getRule(): Rule
{
Expand Down
Loading

0 comments on commit acd6894

Please sign in to comment.