From c410791f71db05c4f509d1c0e555d0da1143112a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 16 Dec 2015 11:23:58 +0100 Subject: [PATCH 1/3] Extract stuff from command and move it to a service. Also re-org some class in new folder --- app/config/config.yml | 10 ++ src/FeedBundle/Command/FetchItemsCommand.php | 143 +-------------- .../Extractor.php} | 4 +- src/FeedBundle/Content/Import.php | 164 ++++++++++++++++++ src/FeedBundle/Controller/FeedController.php | 2 +- .../Extractor/AbstractExtractor.php | 5 +- src/FeedBundle/Resources/config/services.yml | 23 ++- .../Tests/Command/FetchItemsCommandTest.php | 26 ++- .../ExtractorTest.php} | 10 +- .../RssRenderTest.php => Xml/RenderTest.php} | 12 +- .../{Services => Xml}/SimplePieProxyTest.php | 6 +- .../{ => Xml}/Formatter/AtomFormatter.php | 2 +- .../{ => Xml}/Formatter/Formatter.php | 2 +- .../{ => Xml}/Formatter/RssFormatter.php | 2 +- .../RssRender.php => Xml/Render.php} | 5 +- .../{Services => Xml}/SimplePieProxy.php | 2 +- 16 files changed, 248 insertions(+), 170 deletions(-) rename src/FeedBundle/{Services/ContentExtractor.php => Content/Extractor.php} (98%) create mode 100644 src/FeedBundle/Content/Import.php rename src/FeedBundle/Tests/{Services/ContentExtractorTest.php => Content/ExtractorTest.php} (93%) rename src/FeedBundle/Tests/{Services/RssRenderTest.php => Xml/RenderTest.php} (87%) rename src/FeedBundle/Tests/{Services => Xml}/SimplePieProxyTest.php (75%) rename src/FeedBundle/{ => Xml}/Formatter/AtomFormatter.php (98%) rename src/FeedBundle/{ => Xml}/Formatter/Formatter.php (98%) rename src/FeedBundle/{ => Xml}/Formatter/RssFormatter.php (98%) rename src/FeedBundle/{Services/RssRender.php => Xml/Render.php} (95%) rename src/FeedBundle/{Services => Xml}/SimplePieProxy.php (97%) diff --git a/app/config/config.yml b/app/config/config.yml index cb8c3830..c2f06da4 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -51,3 +51,13 @@ stof_doctrine_extensions: default: timestampable: true sluggable: true + +monolog: + channels: ['import'] + handlers: + console: + type: console + verbosity_levels: + VERBOSITY_NORMAL: DEBUG + channels: import + formatter: monolog.import.formatter diff --git a/src/FeedBundle/Command/FetchItemsCommand.php b/src/FeedBundle/Command/FetchItemsCommand.php index 08808e2a..05371c45 100644 --- a/src/FeedBundle/Command/FetchItemsCommand.php +++ b/src/FeedBundle/Command/FetchItemsCommand.php @@ -7,12 +7,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\LockHandler; -use Symfony\Component\Console\Helper\ProgressBar; -use Api43\FeedBundle\Document\Feed; -use Api43\FeedBundle\Document\FeedItem; -use Api43\FeedBundle\Document\FeedLog; -use Api43\FeedBundle\Event\FeedItemEvent; -use Api43\FeedBundle\Api43FeedEvents; +use Symfony\Component\Console\Logger\ConsoleLogger; class FetchItemsCommand extends ContainerAwareCommand { @@ -74,140 +69,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Feeds to check: '.count($feeds)); } - $totalCached = 0; - $feedUpdated = array(); - - foreach ($feeds as $feed) { - if ($output->isVerbose()) { - $output->writeln('Working on: '.$feed->getName().' (parser: '.$feed->getParser().')'); - } - - $rssFeed = $container - ->get('simple_pie_proxy') - ->setUrl($feed->getLink()) - ->init(); - - // update feed description, in case it was empty - if (0 === strlen($feed->getDescription()) && 0 !== strlen($rssFeed->get_description())) { - $feed->setDescription(html_entity_decode($rssFeed->get_description(), ENT_COMPAT, 'UTF-8')); - $dm->persist($feed); - $dm->flush($feed); - } - - $parser = $container - ->get('content_extractor') - ->init($feed->getParser(), $feed, true); - - $cachedLinks = $feedItemRepo->getAllLinks($feed->getId()); - $cached = 0; - - // show progress bar in trace mode only - if ($output->isVerbose()) { - $total = $rssFeed->get_item_quantity(); - $progress = new ProgressBar($output, $total); - $progress->start(); - } - - foreach ($rssFeed->get_items() as $item) { - if ($output->isVerbose()) { - $progress->advance(); - } - - // if an item already exists, we skip it - // or if the item doesn't have a link, we won't cache it - will be useless - if (isset($cachedLinks[$item->get_permalink()]) || null === $item->get_permalink()) { - continue; - } - - $parsedContent = $parser->parseContent( - $item->get_permalink(), - $item->get_description() - ); - - // if readable content failed, use default one from feed item - $content = $parsedContent->content; - if (false === $content) { - $content = $item->get_content(); - } - - // if there is no date in the feed, we use the current one - $date = $item->get_date(); - if (null === $date) { - $date = date('j F Y, g:i:s a'); - } - - $feedItem = new FeedItem(); - $feedItem->setTitle(html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8')); - $feedItem->setLink($parsedContent->url); - $feedItem->setContent($content); - $feedItem->setPermalink($item->get_permalink()); - $feedItem->setPublishedAt($date); - $feedItem->setFeed($feed); - $dm->persist($feedItem); - - ++$cached; - } - - if ($output->isVerbose()) { - $progress->finish(); - $output->writeln(''); - } - - if ($cached) { - // save the last time items where updated - $feed->setLastItemCachedAt(date('j F Y, g:i:s a')); - $dm->persist($feed); - - $totalCached += $cached; - - $feedLog = new FeedLog(); - $feedLog->setItemsNumber($cached); - $feedLog->setFeed($feed); - - $dm->persist($feedLog); - - // store feed url updated, to ping hub later - $feedUpdated[] = $feed->getSlug(); - } - - if ($output->isVerbose()) { - $output->writeln('New cached items: '.$cached); - } - - $dm->flush(); - } - - if (!empty($feedUpdated)) { - if ($output->isVerbose()) { - $output->writeln('Ping hubs...'); - } - - // send an event about new feed updated - $event = new FeedItemEvent($feedUpdated); - - $container->get('event_dispatcher')->dispatch( - Api43FeedEvents::AFTER_ITEM_CACHED, - $event - ); - } + // let's import some stuff ! + $import = $container->get('content_import'); + $totalCached = $import->process($feeds); $output->writeLn(''.$totalCached.' items cached.'); - - // update nb items for each udpated feed - foreach ($feedUpdated as $slug) { - $feed = $feedRepo->findOneByslug($slug); - - $nbItems = $feedItemRepo->countByFeedId($feed->getId()); - - $feed->setNbItems($nbItems); - $dm->persist($feed); - - if ($output->isVerbose()) { - $output->writeln(''.$feed->getName().' items updated: '.$nbItems.''); - } - } - - $dm->flush(); - $dm->clear(); } } diff --git a/src/FeedBundle/Services/ContentExtractor.php b/src/FeedBundle/Content/Extractor.php similarity index 98% rename from src/FeedBundle/Services/ContentExtractor.php rename to src/FeedBundle/Content/Extractor.php index b0976655..46afc089 100644 --- a/src/FeedBundle/Services/ContentExtractor.php +++ b/src/FeedBundle/Content/Extractor.php @@ -1,13 +1,13 @@ simplePieProxy = $simplePieProxy; + $this->extractor = $extractor; + $this->eventDispatcher = $eventDispatcher; + $this->dm = $dm; + $this->logger = $logger; + } + + /** + * Process feeds in parameter: + * - fetch xml feed + * - retrieve all links inside it + * - extract content + * - create a FeedItem with all information + * - a FeedLog with all item cached + * - if there are new content, dispatch event to ping hub + * - finally, update total item counter. + * + * @param array $feeds An array for Api43\FeedBundle\Document\Feed or an Doctrine\ODM\MongoDB\EagerCursor + */ + public function process($feeds) + { + $totalCached = 0; + $feedUpdated = array(); + $feedRepo = $this->dm->getRepository('Api43FeedBundle:Feed'); + $feedItemRepo = $this->dm->getRepository('Api43FeedBundle:FeedItem'); + + foreach ($feeds as $feed) { + $this->logger->debug('Working on: '.$feed->getName().' (parser: '.$feed->getParser().')'); + + $rssFeed = $this + ->simplePieProxy + ->setUrl($feed->getLink()) + ->init(); + + // update feed description, in case it was empty + if (0 === strlen($feed->getDescription()) && 0 !== strlen($rssFeed->get_description())) { + $feed->setDescription(html_entity_decode($rssFeed->get_description(), ENT_COMPAT, 'UTF-8')); + $this->dm->persist($feed); + $this->dm->flush($feed); + } + + $parser = $this + ->extractor + ->init($feed->getParser(), $feed, true); + + $cachedLinks = $feedItemRepo->getAllLinks($feed->getId()); + $cached = 0; + + $this->logger->debug('Link to check: '.$rssFeed->get_item_quantity().''); + + foreach ($rssFeed->get_items() as $item) { + // if an item already exists, we skip it + // or if the item doesn't have a link, we won't cache it - will be useless + if (isset($cachedLinks[$item->get_permalink()]) || null === $item->get_permalink()) { + continue; + } + + $this->logger->debug(' Parse content for url: '.$item->get_permalink().''); + + $parsedContent = $parser->parseContent( + $item->get_permalink(), + $item->get_description() + ); + + // if readable content failed, use default one from feed item + $content = $parsedContent->content; + if (false === $content) { + $content = $item->get_content(); + } + + // if there is no date in the feed, we use the current one + $date = $item->get_date(); + if (null === $date) { + $date = date('j F Y, g:i:s a'); + } + + $feedItem = new FeedItem(); + $feedItem->setTitle(html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8')); + $feedItem->setLink($parsedContent->url); + $feedItem->setContent($content); + $feedItem->setPermalink($item->get_permalink()); + $feedItem->setPublishedAt($date); + $feedItem->setFeed($feed); + $this->dm->persist($feedItem); + + ++$cached; + } + + if ($cached) { + // save the last time items where updated + $feed->setLastItemCachedAt(date('j F Y, g:i:s a')); + $this->dm->persist($feed); + + $totalCached += $cached; + + $feedLog = new FeedLog(); + $feedLog->setItemsNumber($cached); + $feedLog->setFeed($feed); + + $this->dm->persist($feedLog); + + // store feed url updated, to ping hub later + $feedUpdated[] = $feed->getSlug(); + } + + $this->logger->debug('New cached items: '.$cached); + + $this->dm->flush(); + } + + if (!empty($feedUpdated)) { + $this->logger->debug('Ping hubs...'); + + // send an event about new feed updated + $event = new FeedItemEvent($feedUpdated); + + $this->eventDispatcher->dispatch( + Api43FeedEvents::AFTER_ITEM_CACHED, + $event + ); + } + + // update nb items for each udpated feed + foreach ($feedUpdated as $slug) { + $feed = $feedRepo->findOneByslug($slug); + + $nbItems = $feedItemRepo->countByFeedId($feed->getId()); + + $feed->setNbItems($nbItems); + $this->dm->persist($feed); + + $this->logger->debug(''.$feed->getName().' items updated: '.$nbItems.''); + } + + $this->dm->flush(); + $this->dm->clear(); + + return $totalCached; + } +} diff --git a/src/FeedBundle/Controller/FeedController.php b/src/FeedBundle/Controller/FeedController.php index 899d043c..1d20643f 100644 --- a/src/FeedBundle/Controller/FeedController.php +++ b/src/FeedBundle/Controller/FeedController.php @@ -204,7 +204,7 @@ private function createDeleteForm() public function xmlAction(Feed $feed) { return new Response( - $this->get('rss_render')->render($feed), + $this->get('xml_render')->render($feed), 200, array('Content-Type' => 'text/xml') ); diff --git a/src/FeedBundle/Extractor/AbstractExtractor.php b/src/FeedBundle/Extractor/AbstractExtractor.php index bd56d76a..caa939db 100644 --- a/src/FeedBundle/Extractor/AbstractExtractor.php +++ b/src/FeedBundle/Extractor/AbstractExtractor.php @@ -3,15 +3,16 @@ namespace Api43\FeedBundle\Extractor; use Psr\Log\LoggerInterface; +use Psr\Log\LoggerAwareInterface; use GuzzleHttp\Client; -abstract class AbstractExtractor +abstract class AbstractExtractor implements LoggerAwareInterface { protected $logger; protected $client; /** - * @param LoggerInterface $logger + * {@inheritdoc} */ public function setLogger(LoggerInterface $logger) { diff --git a/src/FeedBundle/Resources/config/services.yml b/src/FeedBundle/Resources/config/services.yml index 7d166fd4..f6a9096c 100644 --- a/src/FeedBundle/Resources/config/services.yml +++ b/src/FeedBundle/Resources/config/services.yml @@ -43,22 +43,37 @@ services: oauth_token_secret: %twitter.access_token_secret% output_format: 'array' + content_import: + class: Api43\FeedBundle\Content\Import + arguments: + - "@simple_pie_proxy" + - "@content_extractor" + - "@event_dispatcher" + - "@doctrine.odm.mongodb.document_manager" + - "@monolog.logger.import" + + # custom formatter for import commande (below) + monolog.import.formatter: + class: Symfony\Bridge\Monolog\Formatter\ConsoleFormatter + arguments: + - "[%%datetime%%] %%start_tag%%%%message%%%%end_tag%% %%context%% %%extra%%\n" + content_extractor: - class: Api43\FeedBundle\Services\ContentExtractor + class: Api43\FeedBundle\Content\Extractor arguments: extractor: "@feed.extractor.chain" improver: "@feed.improver.chain" parser: "@feed.parser.chain" simple_pie_proxy: - class: Api43\FeedBundle\Services\SimplePieProxy + class: Api43\FeedBundle\Xml\SimplePieProxy arguments: cache: "%kernel.root_dir%/cache/simplepie/" item_limit: 20 enable_cache: false - rss_render: - class: Api43\FeedBundle\Services\RssRender + xml_render: + class: Api43\FeedBundle\Xml\Render arguments: generator: %domain% doctrine: "@doctrine.odm.mongodb.document_manager" diff --git a/src/FeedBundle/Tests/Command/FetchItemsCommandTest.php b/src/FeedBundle/Tests/Command/FetchItemsCommandTest.php index 147fac96..9445261b 100644 --- a/src/FeedBundle/Tests/Command/FetchItemsCommandTest.php +++ b/src/FeedBundle/Tests/Command/FetchItemsCommandTest.php @@ -7,6 +7,8 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Output\OutputInterface; +use Monolog\Logger; +use Monolog\Handler\TestHandler; class FetchItemsCommandTest extends WebTestCase { @@ -47,7 +49,7 @@ public function setUp() ->method('get_description') ->will($this->returnValue('desc')); - $simplePieProxy = $this->getMockBuilder('Api43\FeedBundle\Services\SimplePieProxy') + $simplePieProxy = $this->getMockBuilder('Api43\FeedBundle\Xml\SimplePieProxy') ->disableOriginalConstructor() ->getMock(); @@ -60,6 +62,12 @@ public function setUp() ->will($this->returnValue($simplePie)); $client->getContainer()->set('simple_pie_proxy', $simplePieProxy); + + $logger = new Logger('import'); + $this->handler = new TestHandler(); + $logger->pushHandler($this->handler); + + $client->getContainer()->set('monolog.logger.import', $logger); } /** @@ -100,6 +108,12 @@ public function testHN() '--slug' => 'hackernews', ), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE)); + $records = $this->handler->getRecords(); + + $this->assertGreaterThan(0, $records); + $this->assertContains('Working on', $records[0]['message']); + $this->assertContains('HackerNews', $records[0]['message']); + $this->assertRegExp('`items cached.`', $this->commandTester->getDisplay()); } @@ -110,6 +124,11 @@ public function testNew() '--age' => 'new', ), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE)); + $records = $this->handler->getRecords(); + + $this->assertGreaterThan(0, $records); + $this->assertContains('Working on', $records[0]['message']); + $this->assertRegExp('`items cached.`', $this->commandTester->getDisplay()); } @@ -120,6 +139,11 @@ public function testOld() '--age' => 'old', ), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE)); + $records = $this->handler->getRecords(); + + $this->assertGreaterThan(0, $records); + $this->assertContains('Working on', $records[0]['message']); + $this->assertRegExp('`items cached.`', $this->commandTester->getDisplay()); } } diff --git a/src/FeedBundle/Tests/Services/ContentExtractorTest.php b/src/FeedBundle/Tests/Content/ExtractorTest.php similarity index 93% rename from src/FeedBundle/Tests/Services/ContentExtractorTest.php rename to src/FeedBundle/Tests/Content/ExtractorTest.php index 7dc48a46..8c745281 100644 --- a/src/FeedBundle/Tests/Services/ContentExtractorTest.php +++ b/src/FeedBundle/Tests/Content/ExtractorTest.php @@ -1,11 +1,11 @@ method('getParser') ->willReturn($internalParser); - $contentExtractor = new ContentExtractor($extractorChain, $improverChain, $parserChain); + $contentExtractor = new Extractor($extractorChain, $improverChain, $parserChain); $contentExtractor->init('internal', $feed, true); if (true === $customParser) { @@ -158,7 +158,7 @@ public function testInvalidParser() ->disableOriginalConstructor() ->getMock(); - $contentExtractor = new ContentExtractor($extractorChain, $improverChain, new \Api43\FeedBundle\Parser\ParserChain()); + $contentExtractor = new Extractor($extractorChain, $improverChain, new \Api43\FeedBundle\Parser\ParserChain()); $contentExtractor->init('oops'); } } diff --git a/src/FeedBundle/Tests/Services/RssRenderTest.php b/src/FeedBundle/Tests/Xml/RenderTest.php similarity index 87% rename from src/FeedBundle/Tests/Services/RssRenderTest.php rename to src/FeedBundle/Tests/Xml/RenderTest.php index 8ead0c36..6d8d1c7c 100644 --- a/src/FeedBundle/Tests/Services/RssRenderTest.php +++ b/src/FeedBundle/Tests/Xml/RenderTest.php @@ -1,10 +1,10 @@ getMock('Api43\FeedBundle\Document\Feed'); - $render = new RssRender('toto', $this->dm, $this->router); + $render = new Render('toto', $this->dm, $this->router); $render->render($feed); } @@ -60,7 +60,7 @@ public function testRenderAtom() ->method('getFormatter') ->willReturn('atom'); - $render = new RssRender('tata', $this->dm, $this->router); + $render = new Render('tata', $this->dm, $this->router); $content = $render->render($feed); libxml_use_internal_errors(true); @@ -85,7 +85,7 @@ public function testRenderRss() ->method('getFormatter') ->willReturn('rss'); - $render = new RssRender('tata', $this->dm, $this->router); + $render = new Render('tata', $this->dm, $this->router); $content = $render->render($feed); libxml_use_internal_errors(true); diff --git a/src/FeedBundle/Tests/Services/SimplePieProxyTest.php b/src/FeedBundle/Tests/Xml/SimplePieProxyTest.php similarity index 75% rename from src/FeedBundle/Tests/Services/SimplePieProxyTest.php rename to src/FeedBundle/Tests/Xml/SimplePieProxyTest.php index 6822d018..c8ffd57e 100644 --- a/src/FeedBundle/Tests/Services/SimplePieProxyTest.php +++ b/src/FeedBundle/Tests/Xml/SimplePieProxyTest.php @@ -1,8 +1,8 @@ setUrl('http://test.com'); $feed = $proxy->init(); - $this->assertEquals('Api43\FeedBundle\Services\SimplePieProxy', get_class($res)); + $this->assertEquals('Api43\FeedBundle\Xml\SimplePieProxy', get_class($res)); $this->assertEquals('SimplePie', get_class($feed)); } } diff --git a/src/FeedBundle/Formatter/AtomFormatter.php b/src/FeedBundle/Xml/Formatter/AtomFormatter.php similarity index 98% rename from src/FeedBundle/Formatter/AtomFormatter.php rename to src/FeedBundle/Xml/Formatter/AtomFormatter.php index 797a714d..8257b890 100644 --- a/src/FeedBundle/Formatter/AtomFormatter.php +++ b/src/FeedBundle/Xml/Formatter/AtomFormatter.php @@ -1,6 +1,6 @@ Date: Wed, 16 Dec 2015 11:47:26 +0100 Subject: [PATCH 2/3] CS And remove nextinpact url since they are now behind CloudFlare which return a 503 "Checking your browser before accessing nextinpact.com." --- src/FeedBundle/Command/FetchItemsCommand.php | 1 - src/FeedBundle/Content/Import.php | 1 - src/FeedBundle/Tests/Controller/FeedTestControllerTest.php | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/FeedBundle/Command/FetchItemsCommand.php b/src/FeedBundle/Command/FetchItemsCommand.php index 05371c45..56a02434 100644 --- a/src/FeedBundle/Command/FetchItemsCommand.php +++ b/src/FeedBundle/Command/FetchItemsCommand.php @@ -7,7 +7,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\LockHandler; -use Symfony\Component\Console\Logger\ConsoleLogger; class FetchItemsCommand extends ContainerAwareCommand { diff --git a/src/FeedBundle/Content/Import.php b/src/FeedBundle/Content/Import.php index bfc40093..64db3470 100644 --- a/src/FeedBundle/Content/Import.php +++ b/src/FeedBundle/Content/Import.php @@ -4,7 +4,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Doctrine\ODM\MongoDB\DocumentManager; -use Psr\Log\NullLogger; use Psr\Log\LoggerInterface; use Api43\FeedBundle\Xml\SimplePieProxy; use Api43\FeedBundle\Document\FeedItem; diff --git a/src/FeedBundle/Tests/Controller/FeedTestControllerTest.php b/src/FeedBundle/Tests/Controller/FeedTestControllerTest.php index 8b13f5d6..fdc78633 100644 --- a/src/FeedBundle/Tests/Controller/FeedTestControllerTest.php +++ b/src/FeedBundle/Tests/Controller/FeedTestControllerTest.php @@ -28,7 +28,7 @@ public function testFeedTestSubmit() $form = $crawler->filter('form.custom button[type=submit]')->form(); $crawler = $client->submit($form, array( - 'item_test[link]' => 'http://www.nextinpact.com/news/89458-gouvernement-valls2-fleur-pellerin-a-culture.htm', + 'item_test[link]' => 'http://www.lemonde.fr/planete/article/2015/12/16/bisphenol-a-phtalates-pesticides-bruxelles-condamnee-pour-son-inaction_4833090_3244.html', 'item_test[parser]' => 'internal', )); @@ -46,7 +46,7 @@ public function testFeedTestSubmitWithSiteConfig() $form = $crawler->filter('form.custom button[type=submit]')->form(); $crawler = $client->submit($form, array( - 'item_test[link]' => 'http://www.nextinpact.com/news/89458-gouvernement-valls2-fleur-pellerin-a-culture.htm', + 'item_test[link]' => 'http://www.lemonde.fr/planete/article/2015/12/16/bisphenol-a-phtalates-pesticides-bruxelles-condamnee-pour-son-inaction_4833090_3244.html', 'item_test[parser]' => 'internal', 'item_test[siteconfig]' => 'body: //body', )); From 000dd43db9ab4429344918a2263bee3bf8aace24 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 16 Dec 2015 12:03:58 +0100 Subject: [PATCH 3/3] CS Mostly from Scrutinizer --- src/FeedBundle/Content/Extractor.php | 4 ++-- src/FeedBundle/Controller/FeedController.php | 2 +- .../Controller/FeedTestController.php | 2 +- src/FeedBundle/Document/Feed.php | 24 +++++++++---------- src/FeedBundle/Document/FeedItem.php | 4 ++-- src/FeedBundle/Document/FeedLog.php | 4 ++-- src/FeedBundle/Tests/Xml/RenderTest.php | 6 ++--- src/FeedBundle/Xml/Render.php | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/FeedBundle/Content/Extractor.php b/src/FeedBundle/Content/Extractor.php index 46afc089..5b72d4e6 100644 --- a/src/FeedBundle/Content/Extractor.php +++ b/src/FeedBundle/Content/Extractor.php @@ -42,7 +42,7 @@ public function __construct(ExtractorChain $extractorChain, ImproverChain $impro * @param bool $allowAllParser Define if we have to use all *known* parser to get the content if the defined one failed. * For example, Internal parser can't make content readable, it will use the External one, etc .. * - * @return ContentExtractor Current object + * @return Extractor Current object */ public function init($chosenParser, Feed $feed = null, $allowAllParser = false) { @@ -63,7 +63,7 @@ public function init($chosenParser, Feed $feed = null, $allowAllParser = false) * @param string $url RSS item url * @param string|null $itemContent RSS item content, which will be taken if we can't extract content from url * - * @return ContentExtractor + * @return Extractor */ public function parseContent($url, $itemContent = null) { diff --git a/src/FeedBundle/Controller/FeedController.php b/src/FeedBundle/Controller/FeedController.php index 1d20643f..9a328ff3 100644 --- a/src/FeedBundle/Controller/FeedController.php +++ b/src/FeedBundle/Controller/FeedController.php @@ -204,7 +204,7 @@ private function createDeleteForm() public function xmlAction(Feed $feed) { return new Response( - $this->get('xml_render')->render($feed), + $this->get('xml_render')->doRender($feed), 200, array('Content-Type' => 'text/xml') ); diff --git a/src/FeedBundle/Controller/FeedTestController.php b/src/FeedBundle/Controller/FeedTestController.php index c2b559fb..42a0aa6e 100644 --- a/src/FeedBundle/Controller/FeedTestController.php +++ b/src/FeedBundle/Controller/FeedTestController.php @@ -17,7 +17,7 @@ class FeedTestController extends Controller * - chose the best parser * - test a site configuration. * - * @return array + * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { diff --git a/src/FeedBundle/Document/Feed.php b/src/FeedBundle/Document/Feed.php index 35c2b051..01b57151 100644 --- a/src/FeedBundle/Document/Feed.php +++ b/src/FeedBundle/Document/Feed.php @@ -277,9 +277,9 @@ public function __construct() /** * Add feeditems. * - * @param \Api43\FeedBundle\Document\FeedItem $feeditems + * @param FeedItem $feeditems */ - public function addFeeditem(\Api43\FeedBundle\Document\FeedItem $feeditems) + public function addFeeditem(FeedItem $feeditems) { $this->feeditems[] = $feeditems; } @@ -287,9 +287,9 @@ public function addFeeditem(\Api43\FeedBundle\Document\FeedItem $feeditems) /** * Remove feeditems. * - * @param \Api43\FeedBundle\Document\FeedItem $feeditems + * @param FeedItem $feeditems */ - public function removeFeeditem(\Api43\FeedBundle\Document\FeedItem $feeditems) + public function removeFeeditem(FeedItem $feeditems) { $this->feeditems->removeElement($feeditems); } @@ -297,7 +297,7 @@ public function removeFeeditem(\Api43\FeedBundle\Document\FeedItem $feeditems) /** * Get feeditems. * - * @return Doctrine\Common\Collections\Collection $feeditems + * @return \Doctrine\Common\Collections\ArrayCollection $feeditems */ public function getFeeditems() { @@ -331,9 +331,9 @@ public function getParser() /** * Add feedlogs. * - * @param \Api43\FeedBundle\Document\FeedLog $feedlogs + * @param FeedLog $feedlogs */ - public function addFeedlog(\Api43\FeedBundle\Document\FeedLog $feedlogs) + public function addFeedlog(FeedLog $feedlogs) { $this->feedlogs[] = $feedlogs; } @@ -341,9 +341,9 @@ public function addFeedlog(\Api43\FeedBundle\Document\FeedLog $feedlogs) /** * Remove feedlogs. * - * @param \Api43\FeedBundle\Document\FeedLog $feedlogs + * @param FeedLog $feedlogs */ - public function removeFeedlog(\Api43\FeedBundle\Document\FeedLog $feedlogs) + public function removeFeedlog(FeedLog $feedlogs) { $this->feedlogs->removeElement($feedlogs); } @@ -351,7 +351,7 @@ public function removeFeedlog(\Api43\FeedBundle\Document\FeedLog $feedlogs) /** * Get feedlogs. * - * @return Doctrine\Common\Collections\Collection $feedlogs + * @return FeedLog[] $feedlogs */ public function getFeedlogs() { @@ -464,7 +464,7 @@ public function getSortBy() /** * Set lastItemCachedAt. * - * @param date $lastItemCachedAt + * @param \DateTime $lastItemCachedAt * * @return self */ @@ -478,7 +478,7 @@ public function setLastItemCachedAt($lastItemCachedAt) /** * Get lastItemCachedAt. * - * @return date $lastItemCachedAt + * @return \DateTime $lastItemCachedAt */ public function getLastItemCachedAt() { diff --git a/src/FeedBundle/Document/FeedItem.php b/src/FeedBundle/Document/FeedItem.php index 033d4d9c..9335233b 100644 --- a/src/FeedBundle/Document/FeedItem.php +++ b/src/FeedBundle/Document/FeedItem.php @@ -227,11 +227,11 @@ public function getPermalink() /** * Set feed. * - * @param \Api43\FeedBundle\Document\Feed $feed + * @param Feed $feed * * @return self */ - public function setFeed(\Api43\FeedBundle\Document\Feed $feed) + public function setFeed(Feed $feed) { $this->feed = $feed; diff --git a/src/FeedBundle/Document/FeedLog.php b/src/FeedBundle/Document/FeedLog.php index f6b51def..e073af3c 100644 --- a/src/FeedBundle/Document/FeedLog.php +++ b/src/FeedBundle/Document/FeedLog.php @@ -100,11 +100,11 @@ public function getCreatedAt() /** * Set feed. * - * @param \Api43\FeedBundle\Document\Feed $feed + * @param Feed $feed * * @return self */ - public function setFeed(\Api43\FeedBundle\Document\Feed $feed) + public function setFeed(Feed $feed) { $this->feed = $feed; diff --git a/src/FeedBundle/Tests/Xml/RenderTest.php b/src/FeedBundle/Tests/Xml/RenderTest.php index 6d8d1c7c..b79a3fbf 100644 --- a/src/FeedBundle/Tests/Xml/RenderTest.php +++ b/src/FeedBundle/Tests/Xml/RenderTest.php @@ -46,7 +46,7 @@ public function testRenderBadFormat() $feed = $this->getMock('Api43\FeedBundle\Document\Feed'); $render = new Render('toto', $this->dm, $this->router); - $render->render($feed); + $render->doRender($feed); } public function testRenderAtom() @@ -61,7 +61,7 @@ public function testRenderAtom() ->willReturn('atom'); $render = new Render('tata', $this->dm, $this->router); - $content = $render->render($feed); + $content = $render->doRender($feed); libxml_use_internal_errors(true); @@ -86,7 +86,7 @@ public function testRenderRss() ->willReturn('rss'); $render = new Render('tata', $this->dm, $this->router); - $content = $render->render($feed); + $content = $render->doRender($feed); libxml_use_internal_errors(true); diff --git a/src/FeedBundle/Xml/Render.php b/src/FeedBundle/Xml/Render.php index 18cb0de4..7aad5fa4 100644 --- a/src/FeedBundle/Xml/Render.php +++ b/src/FeedBundle/Xml/Render.php @@ -34,7 +34,7 @@ public function __construct($generator, DocumentManager $dm, Router $router) * * @throws \InvalidArgumentException if given format formatter does not exists */ - public function render(Feed $feed) + public function doRender(Feed $feed) { $items = $this->dm->getRepository('Api43FeedBundle:FeedItem')->findByFeed( $feed->getId(),