public function addAlternate(PhpType $alternate) { // build() returns the bottom type by default, so we can // just bail out early here. if ($alternate->isNoType()) { return $this; } $this->isAllType = $this->isAllType || $alternate->isAllType(); $isAlternateUnknown = $alternate instanceof UnknownType; // instanceof is desired here $this->isNativeUnknownType = $this->isNativeUnknownType || $isAlternateUnknown; if ($isAlternateUnknown) { $this->areAllUnknownsChecked = $this->areAllUnknownsChecked && $alternate->isChecked(); } if (!$this->isAllType && !$this->isNativeUnknownType) { if ($alternate->isUnionType()) { $union = $alternate->toMaybeUnionType(); foreach ($union->getAlternates() as $unionAlt) { $this->addAlternate($unionAlt); } } else { // Look through the alternates we've got so far, // and check if any of them are duplicates of // one another. foreach ($this->alternates as $index => $current) { // The Unknown type is special in that we cannot use our // subtype based check, but need to check for equality to // avoid duplicates, and not remove all other alternates. if ($alternate->isUnknownType()) { if ($alternate->equals($current)) { return $this; } continue; } // Check if we already have a more general type in the union. // Then, we do not add this alternate. if ($alternate->isSubTypeOf($current)) { return $this; } // Check if we have a subtype of the passed alternate. Then, // we remove that alternate in favor of the newly passed one. if ($current->isSubTypeOf($alternate)) { unset($this->alternates[$index]); } } $this->alternates[] = $alternate; } } return $this; }
/** * @dataProvider getEqualsTests */ public function testEquals(PhpType $a, PhpType $b, $expectedOutcome) { $this->assertSame($expectedOutcome, $a->equals($b)); }
private function hasTypeChanged(PhpType $newType, PhpType $currentType = null) { if (null === $currentType) { return true; } return false === $newType->equals($currentType); }
private function isMoreSpecificType(PhpType $actualType, PhpType $annotatedType) { if ($actualType->equals($annotatedType)) { return false; } if ($actualType->isUnknownType()) { return false; } return $actualType->isSubtypeOf($annotatedType); }