Skip to content

Commit

Permalink
Simplify TemplateTypeTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard van Velzen authored and ondrejmirtes committed Sep 6, 2022
1 parent 42f5747 commit 12e40f1
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 315 deletions.
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\ArrayType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof ArrayType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
16 changes: 0 additions & 16 deletions src/Type/Generic/TemplateBenevolentUnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,4 @@ public function withTypes(array $types): self
);
}

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof BenevolentUnionType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

}
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateBooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\BooleanType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof BooleanType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof ConstantArrayType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateConstantIntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof ConstantIntegerType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateConstantStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof ConstantStringType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateFloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\FloatType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof FloatType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
16 changes: 0 additions & 16 deletions src/Type/Generic/TemplateGenericObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ public function __construct(
$this->bound = $bound;
}

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof GenericObjectType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function recreate(string $className, array $types, ?Type $subtractedType): GenericObjectType
{
return new self(
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateIntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\IntegerType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof IntegerType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function shouldGeneralizeInferredType(): bool
{
return false;
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateIntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPStan\Type\Generic;

use PHPStan\Type\IntersectionType;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof IntersectionType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

}
25 changes: 2 additions & 23 deletions src/Type/Generic/TemplateKeyOfType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,17 @@ public function __construct(
$this->bound = $bound;
}

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof KeyOfType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

protected function getResult(): Type
{
$result = $this->getBound()->getResult();

$type = TemplateTypeFactory::create(
return TemplateTypeFactory::create(
$this->getScope(),
$this->getName(),
$result,
$this->getVariance(),
$this->getStrategy(),
);

if ($this->isArgument()) {
$type = TemplateTypeHelper::toArgument($type);
}

return $type;
}

protected function shouldGeneralizeInferredType(): bool
Expand Down
16 changes: 0 additions & 16 deletions src/Type/Generic/TemplateMixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog
return TrinaryLogic::createYes();
}

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof MixedType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

public function toStrictMixedType(): TemplateStrictMixedType
{
return new TemplateStrictMixedType(
Expand Down
17 changes: 0 additions & 17 deletions src/Type/Generic/TemplateObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Type\ObjectType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;

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

public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof ObjectType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}

return $this;
}

}
Loading

0 comments on commit 12e40f1

Please sign in to comment.