Skip to content

Commit

Permalink
Hide fixed invariance composition behind a bleeding-edge toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripudil authored and ondrejmirtes committed Dec 7, 2022
1 parent 58baae6 commit dc1688e
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 10 deletions.
1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ parameters:
nullContextForVoidReturningFunctions: true
unescapeStrings: true
duplicateStubs: true
invarianceComposition: true
2 changes: 2 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ parameters:
nullContextForVoidReturningFunctions: false
unescapeStrings: false
duplicateStubs: false
invarianceComposition: false
fileExtensions:
- php
checkAdvancedIsset: false
Expand Down Expand Up @@ -272,6 +273,7 @@ parametersSchema:
nullContextForVoidReturningFunctions: bool()
unescapeStrings: bool()
duplicateStubs: bool()
invarianceComposition: bool()
])
fileExtensions: listOf(string())
checkAdvancedIsset: bool()
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Reflection\ReflectionProviderStaticAccessor;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Generic\TemplateTypeVariance;
use Symfony\Component\Finder\Finder;
use function array_diff_key;
use function array_map;
Expand Down Expand Up @@ -174,6 +175,7 @@ public static function postInitializeContainer(Container $container): void

BleedingEdgeToggle::setBleedingEdge($container->getParameter('featureToggles')['bleedingEdge']);
AccessoryArrayListType::setListTypeEnabled($container->getParameter('featureToggles')['listType']);
TemplateTypeVariance::setInvarianceCompositionEnabled($container->getParameter('featureToggles')['invarianceComposition']);
}

public function clearOldContainers(string $tempDirectory): void
Expand Down
9 changes: 8 additions & 1 deletion src/Type/Generic/TemplateTypeVariance.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TemplateTypeVariance
/** @var self[] */
private static array $registry;

private static bool $invarianceCompositionEnabled = false;

private function __construct(private int $value)
{
}
Expand Down Expand Up @@ -93,7 +95,7 @@ public function compose(self $other): self
return self::createInvariant();
}

if ($this->invariant()) {
if (self::$invarianceCompositionEnabled && $this->invariant()) {
return self::createInvariant();
}

Expand Down Expand Up @@ -177,4 +179,9 @@ public static function __set_state(array $properties): self
return new self($properties['value']);
}

public static function setInvarianceCompositionEnabled(bool $enabled): void
{
self::$invarianceCompositionEnabled = $enabled;
}

}
Loading

0 comments on commit dc1688e

Please sign in to comment.