Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b2b8690

Browse files
Union types in properties
1 parent 51a2f7b commit b2b8690

17 files changed

+62
-55
lines changed

‎build/rector-downgrade.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
99
use Rector\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector;
1010
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector;
11+
use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector;
1112
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1213

1314

@@ -38,6 +39,7 @@
3839
if ($targetPhpVersionId < 80000) {
3940
$services->set(DowngradeTrailingCommasInParamUseRector::class);
4041
$services->set(DowngradeNonCapturingCatchesRector::class);
42+
$services->set(DowngradeUnionTypeTypedPropertyRector::class);
4143
}
4244

4345
if ($targetPhpVersionId < 70400) {

‎patches/TypeFactory.patch‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@package rector/rector
2+
3+
--- packages/NodeTypeResolver/PHPStan/Type/TypeFactory.php 2021年11月23日 18:38:29.000000000 +0100
4+
+++ packages/NodeTypeResolver/PHPStan/Type/TypeFactory.php 2021年12月18日 22:49:01.000000000 +0100
5+
@@ -122,9 +122,6 @@
6+
if ($type instanceof \PHPStan\Type\Constant\ConstantIntegerType) {
7+
return new \PHPStan\Type\IntegerType();
8+
}
9+
- if ($type instanceof \PHPStan\Type\Constant\ConstantBooleanType) {
10+
- return new \PHPStan\Type\BooleanType();
11+
- }
12+
return $type;
13+
}
14+
/**

‎phpcs.xml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
4848
<properties>
4949
<property name="enableNativeTypeHint" value="true"/>
50+
<property name="enableUnionTypeHint" value="true"/>
5051
</properties>
5152
</rule>
5253
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation">
@@ -157,6 +158,13 @@
157158
<property name="enable" value="true"/>
158159
</properties>
159160
</rule>
161+
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
162+
<properties>
163+
<property name="enable" value="true"/>
164+
<property name="withSpaces" value="no"/>
165+
<property name="nullPosition" value="last"/>
166+
</properties>
167+
</rule>
160168
<exclude-pattern>tests/*/data</exclude-pattern>
161169
<exclude-pattern>tests/e2e/resultCache_1.php</exclude-pattern>
162170
<exclude-pattern>tests/e2e/resultCache_2.php</exclude-pattern>

‎src/Analyser/Error.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class Error implements JsonSerializable
2020

2121
private ?int $line;
2222

23-
/** @var bool|Throwable */
24-
private $canBeIgnored;
23+
private bool|Throwable $canBeIgnored;
2524

2625
private ?string $filePath;
2726

‎src/Analyser/MutatingScope.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ class MutatingScope implements Scope
171171
/** @var array<string, Type> */
172172
private array $constantTypes;
173173

174-
/** @var FunctionReflection|MethodReflection|null */
175-
private $function;
174+
private FunctionReflection|MethodReflection|null $function = null;
176175

177176
private ?string $namespace;
178177

‎src/Node/BooleanAndNode.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
class BooleanAndNode extends NodeAbstract implements VirtualNode
1212
{
1313

14-
/** @var BooleanAnd|LogicalAnd */
15-
private $originalNode;
14+
private BooleanAnd|LogicalAnd $originalNode;
1615

1716
private Scope $rightScope;
1817

‎src/Node/BooleanOrNode.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
class BooleanOrNode extends NodeAbstract implements VirtualNode
1212
{
1313

14-
/** @var BooleanOr|LogicalOr */
15-
private $originalNode;
14+
private BooleanOr|LogicalOr $originalNode;
1615

1716
private Scope $rightScope;
1817

‎src/Node/ClassPropertyNode.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class ClassPropertyNode extends NodeAbstract implements VirtualNode
1717

1818
private int $flags;
1919

20-
/** @var Identifier|Name|Node\ComplexType|null */
21-
private $type;
20+
private Identifier|Name|Node\ComplexType|null $type = null;
2221

2322
private ?Expr $default;
2423

‎src/Node/FunctionCallableNode.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
class FunctionCallableNode extends Expr implements VirtualNode
1010
{
1111

12-
/** @var Name|Expr */
13-
private $name;
12+
private Name|Expr $name;
1413

1514
/**
1615
* @param Expr|Name $name

‎src/Node/InstantiationCallableNode.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
class InstantiationCallableNode extends Expr implements VirtualNode
1010
{
1111

12-
/** @var Name|Expr */
13-
private $class;
12+
private Name|Expr $class;
1413

1514
/**
1615
* @param Expr|Name $class

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /