Skip to content

Instantly share code, notes, and snippets.

@schmittjoh
Last active July 22, 2018 13:37
Show Gist options
  • Save schmittjoh/8462371 to your computer and use it in GitHub Desktop.
Save schmittjoh/8462371 to your computer and use it in GitHub Desktop.
Different Ways of Consuming Options
<?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);
})
;
<?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