Default value is intrinsic to a configurable, we can just always

retrieve that.
This commit is contained in:
Aidan Woods 2019-01-25 19:48:03 +00:00
parent 5a50930cb0
commit eb90905d27
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
8 changed files with 9 additions and 29 deletions

View File

@ -78,7 +78,7 @@ final class Comment implements ContinuableBlock
return new Handler(
/** @return Text|RawHtml */
function (State $State) {
if ($State->getOrDefault(SafeMode::class)->isEnabled()) {
if ($State->get(SafeMode::class)->isEnabled()) {
return new Text($this->html);
} else {
return new RawHtml($this->html);

View File

@ -58,10 +58,8 @@ final class Header implements Block
$text = \ltrim($Context->line()->text(), '#');
$StrictMode = $State->getOrDefault(StrictMode::class);
if (
$StrictMode->isEnabled() && isset($text[0])
$State->get(StrictMode::class)->isEnabled() && isset($text[0])
and $text[0] !== ' ' and $text[0] !== "\t"
) {
return null;

View File

@ -76,9 +76,7 @@ final class Markup implements ContinuableBlock
return new Handler(
/** @return Element|RawHtml */
function (State $State) {
$SafeMode = $State->getOrDefault(SafeMode::class);
if ($SafeMode->isEnabled()) {
if ($State->get(SafeMode::class)->isEnabled()) {
return new Element('p', [], [new Text($this->html)]);
} else {
return new RawHtml($this->html);

View File

@ -51,7 +51,7 @@ final class Reference implements StateUpdatingBlock
];
$State = $State->setting(
$State->getOrDefault(DefinitionBook::class)->setting($id, $Data)
$State->get(DefinitionBook::class)->setting($id, $Data)
);
return new self($State);

View File

@ -83,7 +83,7 @@ final class Image implements Inline
$attributes['title'] = $title;
}
if ($State->getOrDefault(SafeMode::class)->isEnabled()) {
if ($State->get(SafeMode::class)->isEnabled()) {
$attributes['src'] = Element::filterUnsafeUrl($attributes['src']);
}

View File

@ -77,7 +77,7 @@ final class Link implements Inline
$definition = \strtolower($label);
}
$data = $State->getOrDefault(DefinitionBook::class)->lookup($definition);
$data = $State->get(DefinitionBook::class)->lookup($definition);
if (! isset($data)) {
return null;
@ -122,7 +122,7 @@ final class Link implements Inline
$attributes['title'] = $this->title;
}
if ($State->getOrDefault(SafeMode::class)->isEnabled()) {
if ($State->get(SafeMode::class)->isEnabled()) {
$attributes['href'] = Element::filterUnsafeUrl($attributes['href']);
}

View File

@ -64,9 +64,7 @@ final class Markup implements Inline
return new Handler(
/** @return Text|RawHtml */
function (State $State) {
$SafeMode = $State->getOrDefault(SafeMode::class);
if ($SafeMode->isEnabled()) {
if ($State->get(SafeMode::class)->isEnabled()) {
return new Text($this->html);
} else {
return new RawHtml($this->html);

View File

@ -43,27 +43,13 @@ final class State
return new self($State->state + $this->state);
}
/**
* @template T as Configurable
* @template-typeof T $configurableClass
* @param class-string<Configurable> $configurableClass
* @return T|null
* */
public function get($configurableClass)
{
return (isset($this->state[$configurableClass])
? $this->state[$configurableClass]
: null
);
}
/**
* @template T as Configurable
* @template-typeof T $configurableClass
* @param class-string<Configurable> $configurableClass
* @return T
* */
public function getOrDefault($configurableClass)
public function get($configurableClass)
{
return (isset($this->state[$configurableClass])
? $this->state[$configurableClass]