Skip to content

Commit

Permalink
Merge pull request #83 from alexdebril/issue/82
Browse files Browse the repository at this point in the history
Fix #82
  • Loading branch information
alexdebril authored May 23, 2017
2 parents e9c89ed + 4cb4b15 commit 0f4f841
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ env:
- PHPUNIT_BIN='vendor/bin/phpunit'
- PHPUNIT_CONFIG='phpunit.xml.dist'
- PHPUNIT_FLAGS='--stop-on-failure --verbose'
- GUZZLE_VERSION="~6.2"

matrix:
include:
Expand All @@ -22,7 +21,8 @@ matrix:
- php: nightly

before_script:
- composer require guzzlehttp/guzzle:${GUZZLE_VERSION}
- composer config --global repo.packagist composer https://packagist.org
- composer install

script : $PHPUNIT_BIN -c $PHPUNIT_CONFIG $PHPUNIT_FLAGS

Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
},
"autoload": {
"psr-4": {"FeedIo\\": "src/FeedIo"}
}
},

"config": {
"preferred-install": {
"*": "dist"
}
}
}
24 changes: 18 additions & 6 deletions src/FeedIo/Reader/Fixer/PublicId.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace FeedIo\Reader\Fixer;

use FeedIo\FeedInterface;
use FeedIo\Feed\NodeInterface;
use FeedIo\Reader\FixerAbstract;

class PublicId extends FixerAbstract
Expand All @@ -22,25 +23,36 @@ class PublicId extends FixerAbstract
*/
public function correct(FeedInterface $feed)
{
if (is_null($feed->getPublicId())) {
$this->logger->notice("correct public id for feed {$feed->getTitle()}");
$feed->setPublicId($feed->getLink());
$this->fixItems($feed);
}
$this->fixNode($feed);

$this->fixItems($feed);

return $this;
}

/**
* @param NodeInterface $node
* @return $this
*/
protected function fixNode(NodeInterface $node)
{
if (is_null($node->getPublicId())) {
$this->logger->notice("correct public id for node {$node->getTitle()}");
$node->setPublicId($node->getLink());
}
}

/**
* @param FeedInterface $feed
* @return $this
*/
protected function fixItems(FeedInterface $feed)
{
foreach ($feed as $item) {
$item->setPublicId($item->getLink());
$this->fixNode($item);
}

return $this;
}

}
12 changes: 10 additions & 2 deletions tests/FeedIo/Reader/Fixer/PublicIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ public function testCorrect()

$this->assertEquals($feed->getLink(), $feed->getPublicId());

foreach ($feed as $item) {
$this->assertEquals($item->getLink(), $item->getPublicId());
foreach ($feed as $idx => $item) {
if ( 0 === $idx )
$this->assertEquals($item->getLink(), $item->getPublicId());
else
$this->assertEquals('2', $item->getPublicId());
}
}

Expand All @@ -47,8 +50,13 @@ protected function getFeed()
$item1 = new Item();
$item1->setLink('http://localhost/1');

$item2 = new Item();
$item2->setLink('http://localhost/2');
$item2->setPublicId('2');

$feed = new Feed();
$feed->add($item1)->setLink('http://localhost/');
$feed->add($item2);

return $feed;
}
Expand Down

0 comments on commit 0f4f841

Please sign in to comment.