Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promoted properties #910

Merged
merged 4 commits into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions build/rector-downgrade.php
Expand Up @@ -7,7 +7,9 @@
use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector;
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
use Rector\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector;
use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector;
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector;
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector;
use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand Down Expand Up @@ -41,6 +43,8 @@
$services->set(DowngradeTrailingCommasInParamUseRector::class);
$services->set(DowngradeNonCapturingCatchesRector::class);
$services->set(DowngradeUnionTypeTypedPropertyRector::class);
$services->set(DowngradePropertyPromotionRector::class);
$services->set(DowngradeUnionTypeDeclarationRector::class);
}

if ($targetPhpVersionId < 70400) {
Expand Down
20 changes: 4 additions & 16 deletions compiler/src/Console/CompileCommand.php
Expand Up @@ -34,26 +34,14 @@
final class CompileCommand extends Command
{

private Filesystem $filesystem;

private ProcessFactory $processFactory;

private string $dataDir;

private string $buildDir;

public function __construct(
Filesystem $filesystem,
ProcessFactory $processFactory,
string $dataDir,
string $buildDir,
private Filesystem $filesystem,
private ProcessFactory $processFactory,
private string $dataDir,
private string $buildDir,
)
{
parent::__construct();
$this->filesystem = $filesystem;
$this->processFactory = $processFactory;
$this->dataDir = $dataDir;
$this->buildDir = $buildDir;
}

protected function configure(): void
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/Filesystem/SymfonyFilesystem.php
Expand Up @@ -9,11 +9,8 @@
final class SymfonyFilesystem implements Filesystem
{

private \Symfony\Component\Filesystem\Filesystem $filesystem;

public function __construct(\Symfony\Component\Filesystem\Filesystem $filesystem)
public function __construct(private \Symfony\Component\Filesystem\Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

public function exists(string $dir): bool
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -56,7 +56,7 @@
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5.4",
"rector/rector": "0.12.5",
"rector/rector": "^0.12.11",
"vaimo/composer-patches": "^4.22"
},
"config": {
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 0 additions & 44 deletions patches/AnonymousFunctionFactory.patch

This file was deleted.

13 changes: 13 additions & 0 deletions patches/BooleanTypeMapper.patch
@@ -0,0 +1,13 @@
@package rector/rector

--- packages/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php 2021-12-31 13:57:22.000000000 +0100
+++ packages/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php 2022-01-05 00:05:20.000000000 +0100
@@ -45,7 +45,7 @@
}
if ($type instanceof \PHPStan\Type\Constant\ConstantBooleanType) {
// cannot be parent of union
- return new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode('true');
+ return new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode('false');
}
return new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode('bool');
}
13 changes: 0 additions & 13 deletions patches/DowngradeTrailingCommasInFunctionCallsRector.patch

This file was deleted.

21 changes: 0 additions & 21 deletions patches/PHPStanNodeScopeResolver.patch

This file was deleted.

14 changes: 0 additions & 14 deletions patches/TypeFactory.patch

This file was deleted.

25 changes: 25 additions & 0 deletions patches/parser.patch
@@ -0,0 +1,25 @@
@package rector/rector

--- config/phpstan/parser.neon 2022-01-05 19:37:59.000000000 +0100
+++ config/phpstan/parser.neon 2022-01-06 21:31:23.000000000 +0100
@@ -5,11 +5,18 @@
factory: @pathRoutingParser
arguments!: []

+ cachedRectorParser:
+ class: PHPStan\Parser\CachedParser
+ arguments:
+ originalParser: @rectorParser
+ cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
+ autowired: false
+
pathRoutingParser:
class: PHPStan\Parser\PathRoutingParser
arguments:
- currentPhpVersionRichParser: @rectorParser
- currentPhpVersionSimpleParser: @rectorParser
+ currentPhpVersionRichParser: @cachedRectorParser
+ currentPhpVersionSimpleParser: @cachedRectorParser
php8Parser: @php8Parser
autowired: false

5 changes: 5 additions & 0 deletions phpcs.xml
Expand Up @@ -165,6 +165,11 @@
<property name="nullPosition" value="last"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion">
<properties>
<property name="enable" value="true"/>
</properties>
</rule>
<exclude-pattern>tests/*/data</exclude-pattern>
<exclude-pattern>tests/*/Fixture</exclude-pattern>
<exclude-pattern>tests/e2e/resultCache_1.php</exclude-pattern>
Expand Down
20 changes: 4 additions & 16 deletions src/Analyser/Analyser.php
Expand Up @@ -18,28 +18,16 @@
class Analyser
{

private FileAnalyser $fileAnalyser;

private Registry $registry;

private NodeScopeResolver $nodeScopeResolver;

private int $internalErrorsCountLimit;

/** @var Error[] */
private array $collectedErrors = [];

public function __construct(
FileAnalyser $fileAnalyser,
Registry $registry,
NodeScopeResolver $nodeScopeResolver,
int $internalErrorsCountLimit,
private FileAnalyser $fileAnalyser,
private Registry $registry,
private NodeScopeResolver $nodeScopeResolver,
private int $internalErrorsCountLimit,
)
{
$this->fileAnalyser = $fileAnalyser;
$this->registry = $registry;
$this->nodeScopeResolver = $nodeScopeResolver;
$this->internalErrorsCountLimit = $internalErrorsCountLimit;
}

/**
Expand Down
30 changes: 5 additions & 25 deletions src/Analyser/AnalyserResult.php
Expand Up @@ -11,32 +11,18 @@ class AnalyserResult
/** @var Error[] */
private array $unorderedErrors;

/** @var Error[] */
private array $errors;

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

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

/** @var array<string, array<ExportedNode>> */
private array $exportedNodes;

private bool $reachedInternalErrorsCountLimit;

/**
* @param Error[] $errors
* @param string[] $internalErrors
* @param array<string, array<string>>|null $dependencies
* @param array<string, array<ExportedNode>> $exportedNodes
*/
public function __construct(
array $errors,
array $internalErrors,
?array $dependencies,
array $exportedNodes,
bool $reachedInternalErrorsCountLimit,
private array $errors,
private array $internalErrors,
private ?array $dependencies,
private array $exportedNodes,
private bool $reachedInternalErrorsCountLimit,
)
{
$this->unorderedErrors = $errors;
Expand All @@ -53,12 +39,6 @@ public function __construct(
$b->getMessage(),
],
);

$this->errors = $errors;
$this->internalErrors = $internalErrors;
$this->dependencies = $dependencies;
$this->exportedNodes = $exportedNodes;
$this->reachedInternalErrorsCountLimit = $reachedInternalErrorsCountLimit;
}

/**
Expand Down
11 changes: 2 additions & 9 deletions src/Analyser/ConditionalExpressionHolder.php
Expand Up @@ -12,24 +12,17 @@
class ConditionalExpressionHolder
{

/** @var array<string, Type> */
private array $conditionExpressionTypes;

private VariableTypeHolder $typeHolder;

/**
* @param array<string, Type> $conditionExpressionTypes
*/
public function __construct(
array $conditionExpressionTypes,
VariableTypeHolder $typeHolder,
private array $conditionExpressionTypes,
private VariableTypeHolder $typeHolder,
)
{
if (count($conditionExpressionTypes) === 0) {
throw new ShouldNotHappenException();
}
$this->conditionExpressionTypes = $conditionExpressionTypes;
$this->typeHolder = $typeHolder;
}

/**
Expand Down