From eb90905d27411986a741f9f6d70e60b2de442d02 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Fri, 25 Jan 2019 19:48:03 +0000 Subject: [PATCH] Default value is intrinsic to a configurable, we can just always retrieve that. --- src/Components/Blocks/Comment.php | 2 +- src/Components/Blocks/Header.php | 4 +--- src/Components/Blocks/Markup.php | 4 +--- src/Components/Blocks/Reference.php | 2 +- src/Components/Inlines/Image.php | 2 +- src/Components/Inlines/Link.php | 4 ++-- src/Components/Inlines/Markup.php | 4 +--- src/State.php | 16 +--------------- 8 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/Components/Blocks/Comment.php b/src/Components/Blocks/Comment.php index 751dd8e..804a2dd 100644 --- a/src/Components/Blocks/Comment.php +++ b/src/Components/Blocks/Comment.php @@ -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); diff --git a/src/Components/Blocks/Header.php b/src/Components/Blocks/Header.php index adb1575..fee2df2 100644 --- a/src/Components/Blocks/Header.php +++ b/src/Components/Blocks/Header.php @@ -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; diff --git a/src/Components/Blocks/Markup.php b/src/Components/Blocks/Markup.php index babc4b6..f82f055 100644 --- a/src/Components/Blocks/Markup.php +++ b/src/Components/Blocks/Markup.php @@ -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); diff --git a/src/Components/Blocks/Reference.php b/src/Components/Blocks/Reference.php index c9ad7f9..aa77b16 100644 --- a/src/Components/Blocks/Reference.php +++ b/src/Components/Blocks/Reference.php @@ -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); diff --git a/src/Components/Inlines/Image.php b/src/Components/Inlines/Image.php index 71cf7c0..85e03ba 100644 --- a/src/Components/Inlines/Image.php +++ b/src/Components/Inlines/Image.php @@ -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']); } diff --git a/src/Components/Inlines/Link.php b/src/Components/Inlines/Link.php index 0d4bdc4..d382bff 100644 --- a/src/Components/Inlines/Link.php +++ b/src/Components/Inlines/Link.php @@ -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']); } diff --git a/src/Components/Inlines/Markup.php b/src/Components/Inlines/Markup.php index ab65ed4..46679d7 100644 --- a/src/Components/Inlines/Markup.php +++ b/src/Components/Inlines/Markup.php @@ -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); diff --git a/src/State.php b/src/State.php index aec242f..c94b9af 100644 --- a/src/State.php +++ b/src/State.php @@ -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 $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 $configurableClass * @return T * */ - public function getOrDefault($configurableClass) + public function get($configurableClass) { return (isset($this->state[$configurableClass]) ? $this->state[$configurableClass]