Skip to content

Commit

Permalink
Create Feed Version enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
jdecool committed May 29, 2017
1 parent cf8ab0c commit 2c2a6f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/Versions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace JDecool\JsonFeed;

final class Versions
{
const VERSION_1 = 'https://jsonfeed.org/version/1';

private function __construct()
{
}
}
8 changes: 4 additions & 4 deletions src/Writer/RendererFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace JDecool\JsonFeed\Writer;

use InvalidArgumentException;
use JDecool\JsonFeed\Versions;

class RendererFactory
{
const VERSION_1 = '1.0';

/** @var array */
private $renderers;

/**
Expand All @@ -24,14 +24,14 @@ public function __construct()
* @param string $version
* @return Version1\Renderer
*/
public function createRenderer($version = self::VERSION_1)
public function createRenderer($version = Versions::VERSION_1)
{
if (isset($this->renderers[$version])) {
return $this->renderers[$version];
}

switch ($version) {
case self::VERSION_1:
case Versions::VERSION_1:
return new Version1\Renderer();
}

Expand Down
5 changes: 2 additions & 3 deletions src/Writer/Version1/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];

Expand Down
3 changes: 2 additions & 1 deletion test/Writer/RendererFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down

0 comments on commit 2c2a6f9

Please sign in to comment.