From 2c2a6f9cfb90152a647397b4b15c8332c91b1b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Sun, 28 May 2017 22:15:10 +0200 Subject: [PATCH] Create Feed Version enum class --- src/Versions.php | 12 ++++++++++++ src/Writer/RendererFactory.php | 8 ++++---- src/Writer/Version1/Renderer.php | 5 ++--- test/Writer/RendererFactoryTest.php | 3 ++- 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/Versions.php diff --git a/src/Versions.php b/src/Versions.php new file mode 100644 index 0000000..ab68051 --- /dev/null +++ b/src/Versions.php @@ -0,0 +1,12 @@ +renderers[$version])) { return $this->renderers[$version]; } switch ($version) { - case self::VERSION_1: + case Versions::VERSION_1: return new Version1\Renderer(); } diff --git a/src/Writer/Version1/Renderer.php b/src/Writer/Version1/Renderer.php index eb6aa28..f83ab78 100644 --- a/src/Writer/Version1/Renderer.php +++ b/src/Writer/Version1/Renderer.php @@ -8,19 +8,18 @@ use JDecool\JsonFeed\Feed; use JDecool\JsonFeed\Hub; use JDecool\JsonFeed\Item; +use JDecool\JsonFeed\Versions; use JDecool\JsonFeed\Writer\RendererInterface; class Renderer implements RendererInterface { - const VERSION_URL = 'https://jsonfeed.org/version/1'; - /** * {@inheritdoc} */ public function render(Feed $feed) { $result = [ - 'version' => self::VERSION_URL, + 'version' => Versions::VERSION_1, 'title' => $feed->getTitle(), ]; diff --git a/test/Writer/RendererFactoryTest.php b/test/Writer/RendererFactoryTest.php index b90caf5..c8a9dd9 100644 --- a/test/Writer/RendererFactoryTest.php +++ b/test/Writer/RendererFactoryTest.php @@ -3,6 +3,7 @@ namespace JDecool\Test\JsonFeed\Writer; use JDecool\JsonFeed\Feed; +use JDecool\JsonFeed\Versions; use JDecool\JsonFeed\Writer\RendererFactory; use PHPUnit\Framework\TestCase; @@ -20,7 +21,7 @@ public function testCreateVersion1Renderer() { $factory = new RendererFactory(); - $renderer = $factory->createRenderer(RendererFactory::VERSION_1); + $renderer = $factory->createRenderer(Versions::VERSION_1); $this->assertInstanceOf('JDecool\JsonFeed\Writer\Version1\Renderer', $renderer); }