Skip to content

Commit

Permalink
Merge branch 'hotfix/penny-arcade'
Browse files Browse the repository at this point in the history
Fixes error handling in PennyArcade source.
  • Loading branch information
weierophinney committed Sep 19, 2015
2 parents 8cd3b4c + a191d3d commit 3bd0e4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Comic.php
Expand Up @@ -2,10 +2,12 @@

namespace PhlyComic;

use JsonSerializable;

/**
* Value object describing a comic
*/
class Comic implements ComicDescription
class Comic implements ComicDescription, JsonSerializable
{
protected $name;
protected $link;
Expand All @@ -21,6 +23,20 @@ public function __construct($name, $link = null, $daily = null, $image = null)
$this->image = $image;
}

/**
* Implemented to allow debugging via json_encode
*/
public function jsonSerialize()
{
return [
'name' => $this->name,
'link' => $this->link,
'daily' => $this->daily,
'image' => $this->image,
'error' => $this->error,
];
}

public function getName()
{
return $this->name;
Expand Down
7 changes: 7 additions & 0 deletions src/ComicSource/PennyArcade.php
Expand Up @@ -2,6 +2,7 @@

namespace PhlyComic\ComicSource;

use PhlyComic\Comic;
use SimpleXMLElement;
use Zend\Dom\Query as DomQuery;

Expand Down Expand Up @@ -38,6 +39,12 @@ protected function getDataFromFeed(SimpleXMLElement $feed)
$link = (string) $latest->link;
$image = $this->getImageFromLink($link);

// If we have a Comic, it's because of an
// error; return it directly.
if ($image instanceof Comic) {
return $image;
}

if ($image) {
return array(
'daily' => $link,
Expand Down

0 comments on commit 3bd0e4f

Please sign in to comment.