Avoid returning objects passed by reference.

Objects are always passed by reference, so it doesn't make sense to
return an object which is passed by reference as it will always be the
same object. This change makes the code a bit more readable.
This commit is contained in:
Jerome Charaoui 2016-12-06 22:17:44 -05:00 committed by Jeremy Benoist
parent 2a0eec07a5
commit 7aba665e48
No known key found for this signature in database
GPG key ID: FB413A58C7715C86
11 changed files with 30 additions and 32 deletions

View file

@ -315,7 +315,7 @@ class EntryRestController extends WallabagRestController
}
try {
$entry = $this->get('wallabag_core.content_proxy')->updateEntry(
$this->get('wallabag_core.content_proxy')->updateEntry(
$entry,
$url,
[
@ -428,7 +428,7 @@ class EntryRestController extends WallabagRestController
$this->validateUserAccess($entry->getUser()->getId());
try {
$entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
$this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
} catch (\Exception $e) {
$this->get('logger')->error('Error while saving an entry', [
'exception' => $e,

View file

@ -53,12 +53,10 @@ class EntryController extends Controller
/**
* Fetch content and update entry.
* In case it fails, entry will return to avod loosing the data.
* In case it fails, $entry->getContent will return an error message.
*
* @param Entry $entry
* @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
*
* @return Entry
*/
private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
{
@ -68,7 +66,7 @@ class EntryController extends Controller
$message = 'flashes.entry.notice.'.$prefixMessage;
try {
$entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
$this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
} catch (\Exception $e) {
$this->get('logger')->error('Error while saving an entry', [
'exception' => $e,
@ -79,8 +77,6 @@ class EntryController extends Controller
}
$this->get('session')->getFlashBag()->add('notice', $message);
return $entry;
}
/**

View file

@ -40,8 +40,6 @@ class ContentProxy
* @param Entry $entry Entry to update
* @param string $url Url to grab content for
* @param array $content An array with AT LEAST keys title, html, url to skip the fetchContent from the url
*
* @return Entry
*/
public function updateEntry(Entry $entry, $url, array $content = [])
{
@ -130,8 +128,6 @@ class ContentProxy
'error_msg' => $e->getMessage(),
]);
}
return $entry;
}
/**

View file

@ -91,13 +91,11 @@ abstract class AbstractImport implements ImportInterface
* @param Entry $entry Entry to update
* @param string $url Url to grab content for
* @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
*
* @return Entry
*/
protected function fetchContent(Entry $entry, $url, array $content = [])
{
try {
return $this->contentProxy->updateEntry($entry, $url, $content);
$this->contentProxy->updateEntry($entry, $url, $content);
} catch (\Exception $e) {
return $entry;
}

View file

@ -201,7 +201,7 @@ abstract class BrowserImport extends AbstractImport
$entry->setTitle($data['title']);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $data['url'], $data);
$this->fetchContent($entry, $data['url'], $data);
if (array_key_exists('tags', $data)) {
$this->tagsAssigner->assignTagsToEntry(

View file

@ -125,7 +125,7 @@ class InstapaperImport extends AbstractImport
$entry->setTitle($importedEntry['title']);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
$this->fetchContent($entry, $importedEntry['url'], $importedEntry);
if (!empty($importedEntry['tags'])) {
$this->tagsAssigner->assignTagsToEntry(

View file

@ -109,7 +109,7 @@ class PinboardImport extends AbstractImport
$entry->setTitle($data['title']);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $data['url'], $data);
$this->fetchContent($entry, $data['url'], $data);
if (!empty($data['tags'])) {
$this->tagsAssigner->assignTagsToEntry(

View file

@ -192,7 +192,7 @@ class PocketImport extends AbstractImport
$entry->setUrl($url);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $url);
$this->fetchContent($entry, $url);
// 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
$entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead);

View file

@ -109,7 +109,7 @@ class ReadabilityImport extends AbstractImport
$entry->setTitle($data['title']);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $data['url'], $data);
$this->fetchContent($entry, $data['url'], $data);
$entry->setArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);

View file

@ -108,7 +108,7 @@ abstract class WallabagImport extends AbstractImport
$entry->setTitle($data['title']);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $data['url'], $data);
$this->fetchContent($entry, $data['url'], $data);
if (array_key_exists('tags', $data)) {
$this->tagsAssigner->assignTagsToEntry(

View file

@ -38,7 +38,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://user@:80');
$this->assertEquals('http://user@:80', $entry->getUrl());
$this->assertEmpty($entry->getTitle());
@ -72,7 +73,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://0.0.0.0');
$this->assertEquals('http://0.0.0.0', $entry->getUrl());
$this->assertEmpty($entry->getTitle());
@ -111,7 +113,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://domain.io');
$this->assertEquals('http://domain.io', $entry->getUrl());
$this->assertEquals('my title', $entry->getTitle());
@ -152,7 +155,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://0.0.0.0');
$this->assertEquals('http://1.1.1.1', $entry->getUrl());
$this->assertEquals('this is my title', $entry->getTitle());
@ -213,8 +217,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
->method('tag');
$proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://0.0.0.0',
[
'html' => str_repeat('this is my content', 325),
@ -251,8 +256,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
->method('tag');
$proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://0.0.0.0',
[
'html' => str_repeat('this is my content', 325),
@ -285,8 +291,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
$logger->pushHandler($handler);
$proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://0.0.0.0',
[
'html' => str_repeat('this is my content', 325),
@ -326,7 +333,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://0.0.0.0', [
'html' => str_repeat('this is my content', 325),
'title' => 'this is my title',
'url' => 'http://1.1.1.1',