Last active
July 22, 2018 13:37
-
-
Save schmittjoh/8462371 to your computer and use it in GitHub Desktop.
Different Ways of Consuming Options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Option::fromValue($this->scope->getTypeOfThis()) | |
->flatMap(function(PhpType $type) { return $type->getObjectTypeMaybe(); }) | |
->map(function(PhpType $type) { | |
if ($type instanceof Clazz && $type->getSuperClassType() instanceof PhpType) { | |
return $type->getSuperClassType(); | |
} | |
return $this->typeRegistry->getNativeType('unknown'); | |
}) | |
->forAll(function(PhpType $type) use ($node) { | |
$node->setAttribute('type', $type); | |
}) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$thisTypeMaybe = Option::fromValue($this->scope->getTypeOfThis()); | |
if ($thisTypeMaybe->isDefined()) { | |
$thisTypeMaybe = $thisTypeMaybe->get()->getObjectTypeMaybe(); | |
if ($thisTypeMaybe->isDefined()) { | |
/** @var PhpType */ | |
$thisType = $thisTypeMaybe->get(); | |
if ($thisType instanceof Clazz && $thisType->getSuperClassType() instanceof PhpType) { | |
$node->setAttribute('type', $thisType->getSuperClassType()); | |
} else { | |
$node->setAttribute('type', $this->typeRegistry->getNativeType('unknown')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment