Skip to content

Commit 12e40f1

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Simplify TemplateTypeTrait
1 parent 42f5747 commit 12e40f1

21 files changed

+34
-315
lines changed

src/Type/Generic/TemplateArrayType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\ArrayType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateArrayType extends ArrayType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof ArrayType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateBenevolentUnionType.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,4 @@ public function withTypes(array $types): self
4141
);
4242
}
4343

44-
public function traverse(callable $cb): Type
45-
{
46-
$newBound = $cb($this->getBound());
47-
if ($this->getBound() !== $newBound && $newBound instanceof BenevolentUnionType) {
48-
return new self(
49-
$this->scope,
50-
$this->strategy,
51-
$this->variance,
52-
$this->name,
53-
$newBound,
54-
);
55-
}
56-
57-
return $this;
58-
}
59-
6044
}

src/Type/Generic/TemplateBooleanType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\BooleanType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateBooleanType extends BooleanType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof BooleanType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateConstantArrayType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\Constant\ConstantArrayType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateConstantArrayType extends ConstantArrayType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof ConstantArrayType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateConstantIntegerType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\Constant\ConstantIntegerType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateConstantIntegerType extends ConstantIntegerType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof ConstantIntegerType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateConstantStringType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\Constant\ConstantStringType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateConstantStringType extends ConstantStringType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof ConstantStringType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateFloatType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\FloatType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateFloatType extends FloatType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof FloatType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateGenericObjectType.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,6 @@ public function __construct(
3030
$this->bound = $bound;
3131
}
3232

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof GenericObjectType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4933
protected function recreate(string $className, array $types, ?Type $subtractedType): GenericObjectType
5034
{
5135
return new self(

src/Type/Generic/TemplateIntegerType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\IntegerType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateIntegerType extends IntegerType implements TemplateType
@@ -30,22 +29,6 @@ public function __construct(
3029
$this->bound = $bound;
3130
}
3231

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof IntegerType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4932
protected function shouldGeneralizeInferredType(): bool
5033
{
5134
return false;

src/Type/Generic/TemplateIntersectionType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Generic;
44

55
use PHPStan\Type\IntersectionType;
6-
use PHPStan\Type\Type;
76

87
/** @api */
98
final class TemplateIntersectionType extends IntersectionType implements TemplateType
@@ -29,20 +28,4 @@ public function __construct(
2928
$this->bound = $bound;
3029
}
3130

32-
public function traverse(callable $cb): Type
33-
{
34-
$newBound = $cb($this->getBound());
35-
if ($this->getBound() !== $newBound && $newBound instanceof IntersectionType) {
36-
return new self(
37-
$this->scope,
38-
$this->strategy,
39-
$this->variance,
40-
$this->name,
41-
$newBound,
42-
);
43-
}
44-
45-
return $this;
46-
}
47-
4831
}

src/Type/Generic/TemplateKeyOfType.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,17 @@ public function __construct(
3030
$this->bound = $bound;
3131
}
3232

33-
public function traverse(callable $cb): Type
34-
{
35-
$newBound = $cb($this->getBound());
36-
if ($this->getBound() !== $newBound && $newBound instanceof KeyOfType) {
37-
return new self(
38-
$this->scope,
39-
$this->strategy,
40-
$this->variance,
41-
$this->name,
42-
$newBound,
43-
);
44-
}
45-
46-
return $this;
47-
}
48-
4933
protected function getResult(): Type
5034
{
5135
$result = $this->getBound()->getResult();
5236

53-
$type = TemplateTypeFactory::create(
37+
return TemplateTypeFactory::create(
5438
$this->getScope(),
5539
$this->getName(),
5640
$result,
5741
$this->getVariance(),
42+
$this->getStrategy(),
5843
);
59-
60-
if ($this->isArgument()) {
61-
$type = TemplateTypeHelper::toArgument($type);
62-
}
63-
64-
return $type;
6544
}
6645

6746
protected function shouldGeneralizeInferredType(): bool

src/Type/Generic/TemplateMixedType.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog
4545
return TrinaryLogic::createYes();
4646
}
4747

48-
public function traverse(callable $cb): Type
49-
{
50-
$newBound = $cb($this->getBound());
51-
if ($this->getBound() !== $newBound && $newBound instanceof MixedType) {
52-
return new self(
53-
$this->scope,
54-
$this->strategy,
55-
$this->variance,
56-
$this->name,
57-
$newBound,
58-
);
59-
}
60-
61-
return $this;
62-
}
63-
6448
public function toStrictMixedType(): TemplateStrictMixedType
6549
{
6650
return new TemplateStrictMixedType(

src/Type/Generic/TemplateObjectType.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Type\ObjectType;
66
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7-
use PHPStan\Type\Type;
87

98
/** @api */
109
final class TemplateObjectType extends ObjectType implements TemplateType
@@ -31,20 +30,4 @@ public function __construct(
3130
$this->bound = $bound;
3231
}
3332

34-
public function traverse(callable $cb): Type
35-
{
36-
$newBound = $cb($this->getBound());
37-
if ($this->getBound() !== $newBound && $newBound instanceof ObjectType) {
38-
return new self(
39-
$this->scope,
40-
$this->strategy,
41-
$this->variance,
42-
$this->name,
43-
$newBound,
44-
);
45-
}
46-
47-
return $this;
48-
}
49-
5033
}

0 commit comments

Comments
 (0)