Commit 2d65e60b authored by alexpott's avatar alexpott

Issue #2191273 by mfernea: Fix Feed typehints in aggregator module.

parent 0fb6dfb4
......@@ -5,7 +5,7 @@
* Used to aggregate syndicated content (RSS, RDF, and Atom).
*/
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Drupal\Component\Plugin\Exception\PluginException;
/**
......@@ -211,10 +211,10 @@ function aggregator_queue_info() {
/**
* Checks a news feed for new items.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* An object describing the feed to be refreshed.
*/
function aggregator_refresh(Feed $feed) {
function aggregator_refresh(FeedInterface $feed) {
// Store feed URL to track changes.
$feed_url = $feed->getUrl();
......@@ -300,7 +300,7 @@ function aggregator_refresh(Feed $feed) {
* @param int $fid
* The feed id.
*
* @return \Drupal\aggregator\Entity\Feed
* @return \Drupal\aggregator\FeedInterface
* An object describing the feed.
*/
function aggregator_feed_load($fid) {
......
......@@ -80,8 +80,8 @@ function theme_aggregator_page_opml($variables) {
*
* @param array $variables
* An associative array containing:
* - source: A Drupal\aggregator\Entity\Feed instance representing
* the feed source.
* - source: A Drupal\aggregator\FeedInterface object representing the feed
* source.
* - summary_items: An array of feed items.
*/
function template_preprocess_aggregator_summary_items(&$variables) {
......@@ -133,8 +133,8 @@ function template_preprocess_aggregator_summary_item(&$variables) {
*
* @param array $variables
* An associative array containing:
* - aggregator_feed: A Drupal\aggregator\Entity\Feed instance
* representing the feed source.
* - aggregator_feed: A Drupal\aggregator\FeedInterface object representing
* the feed source.
*/
function template_preprocess_aggregator_feed_source(&$variables) {
$feed = $variables['aggregator_feed'];
......
......@@ -7,7 +7,7 @@
namespace Drupal\aggregator\Plugin;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
/**
* Defines an interface for aggregator fetcher implementations.
......@@ -23,7 +23,7 @@ interface FetcherInterface {
/**
* Downloads feed data.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* A feed object representing the resource to be downloaded.
* $feed->getUrl() contains the link to the feed.
* Download the data at the URL and expose it
......@@ -32,6 +32,6 @@ interface FetcherInterface {
* @return
* TRUE if fetching was successful, FALSE otherwise.
*/
public function fetch(Feed $feed);
public function fetch(FeedInterface $feed);
}
......@@ -7,7 +7,7 @@
namespace Drupal\aggregator\Plugin;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
/**
* Defines an interface for aggregator parser implementations.
......@@ -24,7 +24,7 @@ interface ParserInterface {
/**
* Parses feed data.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* An object describing the resource to be parsed.
* $feed->source_string->value contains the raw feed data. Parse the data
* and add the following properties to the $feed object:
......@@ -48,6 +48,6 @@ interface ParserInterface {
* @return bool
* TRUE if parsing was successful, FALSE otherwise.
*/
public function parse(Feed $feed);
public function parse(FeedInterface $feed);
}
......@@ -7,7 +7,7 @@
namespace Drupal\aggregator\Plugin;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
/**
* Defines an interface for aggregator processor implementations.
......@@ -23,15 +23,14 @@ interface ProcessorInterface {
/**
* Processes feed data.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* A feed object representing the resource to be processed.
* $feed->items contains an array of feed items downloaded and parsed at the
* parsing stage. See \Drupal\aggregator\Plugin\FetcherInterface::parse()
* for the basic format of a single item in the $feed->items array.
* For the exact format refer to the particular parser in use.
*
*/
public function process(Feed $feed);
public function process(FeedInterface $feed);
/**
* Refreshes feed information.
......@@ -39,12 +38,12 @@ public function process(Feed $feed);
* Called after the processing of the feed is completed by all selected
* processors.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* Object describing feed.
*
* @see aggregator_refresh()
*/
public function postProcess(Feed $feed);
public function postProcess(FeedInterface $feed);
/**
* Removes stored feed data.
......@@ -52,10 +51,9 @@ public function postProcess(Feed $feed);
* Called by aggregator if either a feed is deleted or a user clicks on
* "remove items".
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* The $feed object whose items are being removed.
*
*/
public function remove(Feed $feed);
public function remove(FeedInterface $feed);
}
......@@ -8,7 +8,7 @@
namespace Drupal\aggregator\Plugin\aggregator\fetcher;
use Drupal\aggregator\Plugin\FetcherInterface;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Guzzle\Http\ClientInterface;
use Guzzle\Http\Exception\BadResponseException;
......@@ -57,7 +57,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function fetch(Feed $feed) {
public function fetch(FeedInterface $feed) {
$request = $this->httpClient->get($feed->getUrl());
$feed->source_string = FALSE;
......
......@@ -8,7 +8,7 @@
namespace Drupal\aggregator\Plugin\aggregator\parser;
use Drupal\aggregator\Plugin\ParserInterface;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Cache\Cache;
use Zend\Feed\Reader\Reader;
use Zend\Feed\Reader\Exception\ExceptionInterface;
......@@ -29,7 +29,7 @@ class DefaultParser implements ParserInterface {
/**
* {@inheritdoc}
*/
public function parse(Feed $feed) {
public function parse(FeedInterface $feed) {
// Set our bridge extension manager to Zend Feed.
Reader::setExtensionManager(\Drupal::service('feed.bridge.reader'));
try {
......
......@@ -9,7 +9,7 @@
use Drupal\aggregator\Plugin\AggregatorPluginSettingsBase;
use Drupal\aggregator\Plugin\ProcessorInterface;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -127,7 +127,7 @@ public function submitConfigurationForm(array &$form, array &$form_state) {
/**
* {@inheritdoc}
*/
public function process(Feed $feed) {
public function process(FeedInterface $feed) {
if (!is_array($feed->items)) {
return;
}
......@@ -184,7 +184,7 @@ public function process(Feed $feed) {
/**
* {@inheritdoc}
*/
public function remove(Feed $feed) {
public function remove(FeedInterface $feed) {
$iids = Database::getConnection()->query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchCol();
if ($iids) {
entity_delete_multiple('aggregator_item', $iids);
......@@ -198,7 +198,7 @@ public function remove(Feed $feed) {
*
* Expires items from a feed depending on expiration settings.
*/
public function postProcess(Feed $feed) {
public function postProcess(FeedInterface $feed) {
$aggregator_clear = $this->configuration['items']['expire'];
if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
/**
* Defines a base class for testing the Aggregator module.
......@@ -47,7 +47,7 @@ function setUp() {
* @param array $edit
* Array with additional form fields.
*
* @return \Drupal\aggregator\Entity\Feed $feed
* @return \Drupal\aggregator\FeedInterface
* Full feed object if possible.
*
* @see getFeedEditArray()
......@@ -65,10 +65,10 @@ function createFeed($feed_url = NULL, array $edit = array()) {
/**
* Deletes an aggregator feed.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* Feed object representing the feed.
*/
function deleteFeed(Feed $feed) {
function deleteFeed(FeedInterface $feed) {
$this->drupalPostForm('admin/config/services/aggregator/delete/feed/' . $feed->id(), array(), t('Delete'));
$this->assertRaw(t('The feed %title has been deleted.', array('%title' => $feed->label())), 'Feed deleted successfully.');
}
......@@ -110,7 +110,7 @@ function getFeedEditArray($feed_url = NULL, array $edit = array()) {
* @param array $values
* (optional) Default values to initialize object properties with.
*
* @return \Drupal\aggregator\Entity\Feed
* @return \Drupal\aggregator\FeedInterface
* A feed object.
*/
function getFeedEditObject($feed_url = NULL, array $values = array()) {
......@@ -147,12 +147,12 @@ function getDefaultFeedItemCount() {
* This method simulates a click to
* admin/config/services/aggregator/update/$fid.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* Feed object representing the feed.
* @param int|null $expected_count
* Expected number of feed items. If omitted no check will happen.
*/
function updateFeedItems(Feed $feed, $expected_count = NULL) {
function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
// First, let's ensure we can get to the rss xml.
$this->drupalGet($feed->getUrl());
$this->assertResponse(200, format_string('!url is reachable.', array('!url' => $feed->getUrl())));
......@@ -181,10 +181,10 @@ function updateFeedItems(Feed $feed, $expected_count = NULL) {
/**
* Confirms an item removal from a feed.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* Feed object representing the feed.
*/
function removeFeedItems(Feed $feed) {
function removeFeedItems(FeedInterface $feed) {
$this->drupalPostForm('admin/config/services/aggregator/remove/' . $feed->id(), array(), t('Remove items'));
$this->assertRaw(t('The news items from %title have been removed.', array('%title' => $feed->label())), 'Feed items removed.');
}
......@@ -192,12 +192,12 @@ function removeFeedItems(Feed $feed) {
/**
* Adds and removes feed items and ensure that the count is zero.
*
* @param \Drupal\aggregator\Entity\Feed $feed
* @param \Drupal\aggregator\FeedInterface $feed
* Feed object representing the feed.
* @param int $expected_count
* Expected number of feed items.
*/
function updateAndRemove(Feed $feed, $expected_count) {
function updateAndRemove(FeedInterface $feed, $expected_count) {
$this->updateFeedItems($feed, $expected_count);
$count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
$this->assertTrue($count);
......
......@@ -9,7 +9,7 @@
use Drupal\aggregator\Plugin\FetcherInterface;
use Drupal\aggregator\Plugin\aggregator\fetcher\DefaultFetcher;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Guzzle\Http\Exception\BadResponseException;
/**
......@@ -28,7 +28,7 @@ class TestFetcher extends DefaultFetcher implements FetcherInterface {
/**
* Implements \Drupal\aggregator\Plugin\FetcherInterface::fetch().
*/
public function fetch(Feed $feed) {
public function fetch(FeedInterface $feed) {
if ($feed->label() == 'Do not fetch') {
return FALSE;
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\aggregator_test\Plugin\aggregator\parser;
use Drupal\aggregator\Plugin\ParserInterface;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Drupal\aggregator\Plugin\aggregator\parser\DefaultParser;
/**
......@@ -29,7 +29,7 @@ class TestParser extends DefaultParser implements ParserInterface {
*
* @todo Actually test this.
*/
public function parse(Feed $feed) {
public function parse(FeedInterface $feed) {
return parent::parse($feed);
}
}
......@@ -9,7 +9,7 @@
use Drupal\aggregator\Plugin\AggregatorPluginSettingsBase;
use Drupal\aggregator\Plugin\ProcessorInterface;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -98,7 +98,7 @@ public function submitConfigurationForm(array &$form, array &$form_state) {
/**
* {@inheritdoc}
*/
public function process(Feed $feed) {
public function process(FeedInterface $feed) {
foreach ($feed->items as &$item) {
// Prepend our test string.
$item['title'] = 'testProcessor' . $item['title'];
......@@ -108,7 +108,7 @@ public function process(Feed $feed) {
/**
* {@inheritdoc}
*/
public function remove(Feed $feed) {
public function remove(FeedInterface $feed) {
// Append a random number, just to change the feed description.
$feed->description->value .= rand(0, 10);
}
......@@ -116,7 +116,7 @@ public function remove(Feed $feed) {
/**
* {@inheritdoc}
*/
public function postProcess(Feed $feed) {
public function postProcess(FeedInterface $feed) {
// Double the refresh rate.
$feed->refresh->value *= 2;
$feed->save();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment