From 5b94705cf3918dc7986c6043b1fbe776bf22958f Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 27 Mar 2018 15:35:06 +0200 Subject: Core: Fix compatibility with nextcloud codestyle (#280) --- appinfo/app.php | 4 +- appinfo/routes.php | 4 +- lib/AppInfo/Application.php | 331 ++++++++++++--------- lib/Command/Updater/AfterUpdate.php | 20 +- lib/Command/Updater/AllFeeds.php | 20 +- lib/Command/Updater/BeforeUpdate.php | 20 +- lib/Command/Updater/UpdateFeed.php | 20 +- lib/Config/Config.php | 66 ++-- lib/Config/DependencyException.php | 15 +- lib/Controller/AdminController.php | 121 +++++--- lib/Controller/ApiController.php | 30 +- lib/Controller/EntityApiSerializer.php | 28 +- lib/Controller/ExportController.php | 40 +-- lib/Controller/FeedApiController.php | 76 +++-- lib/Controller/FeedController.php | 123 ++++---- lib/Controller/FolderApiController.php | 41 +-- lib/Controller/FolderController.php | 57 ++-- lib/Controller/ItemApiController.php | 91 +++--- lib/Controller/ItemController.php | 108 ++++--- lib/Controller/JSONHttpError.php | 12 +- lib/Controller/PageController.php | 68 +++-- lib/Controller/UserApiController.php | 25 +- lib/Controller/UtilityApiController.php | 42 +-- lib/Cron/Updater.php | 16 +- lib/Db/EntityJSONSerializer.php | 14 +- lib/Db/Feed.php | 38 ++- lib/Db/FeedMapper.php | 42 ++- lib/Db/FeedType.php | 11 +- lib/Db/Folder.php | 33 +- lib/Db/FolderMapper.php | 39 ++- lib/Db/IAPI.php | 11 +- lib/Db/Item.php | 75 +++-- lib/Db/ItemMapper.php | 116 +++++--- lib/Db/MapperFactory.php | 39 +-- lib/Db/Mysql/ItemMapper.php | 21 +- lib/Db/NewsMapper.php | 47 +-- lib/DependencyInjection/IFactory.php | 12 +- lib/Explore/RecommendedSiteNotFoundException.php | 11 +- lib/Explore/RecommendedSites.php | 19 +- lib/Fetcher/FeedFetcher.php | 180 ++++++----- lib/Fetcher/Fetcher.php | 63 ++-- lib/Fetcher/FetcherException.php | 15 +- lib/Fetcher/IFeedFetcher.php | 43 +-- lib/Fetcher/YoutubeFetcher.php | 49 +-- lib/Hooks/User.php | 14 +- lib/Http/TextDownloadResponse.php | 25 +- lib/Http/TextResponse.php | 23 +- lib/Migration/MigrateStatusFlags.php | 24 +- lib/Plugin/Client/Plugin.php | 23 +- lib/PostProcessor/LWNProcessor.php | 36 ++- lib/Service/FeedService.php | 142 +++++---- lib/Service/FolderService.php | 87 +++--- lib/Service/ItemService.php | 202 +++++++------ lib/Service/Service.php | 30 +- lib/Service/ServiceConflictException.php | 15 +- lib/Service/ServiceException.php | 15 +- lib/Service/ServiceNotFoundException.php | 15 +- lib/Service/ServiceValidationException.php | 15 +- lib/Service/StatusService.php | 20 +- lib/Settings/Admin.php | 15 +- lib/Settings/Section.php | 18 +- lib/Utility/OPMLExporter.php | 25 +- lib/Utility/PicoFeedClientFactory.php | 18 +- lib/Utility/PicoFeedFaviconFactory.php | 18 +- lib/Utility/ProxyConfigParser.php | 18 +- lib/Utility/Time.php | 11 +- lib/Utility/Updater.php | 25 +- tests/Integration/Db/FeedMapperTest.php | 99 ++++-- tests/Integration/Db/FolderMapperTest.php | 8 +- tests/Integration/Db/ItemMapperTest.php | 59 ++-- tests/Integration/Fixtures/FeedFixture.php | 14 +- tests/Integration/Fixtures/Fixture.php | 8 +- tests/Integration/Fixtures/FolderFixture.php | 14 +- tests/Integration/Fixtures/ItemFixture.php | 14 +- tests/Integration/Fixtures/data/default.php | 2 +- tests/Integration/Fixtures/data/readitem.php | 2 +- tests/Integration/IntegrationTest.php | 90 ++++-- tests/Unit/Config/ConfigTest.php | 83 ++++-- tests/Unit/Controller/AdminControllerTest.php | 36 ++- tests/Unit/Controller/EntityApiSerializerTest.php | 32 +- tests/Unit/Controller/ExportControllerTest.php | 41 ++- tests/Unit/Controller/FeedApiControllerTest.php | 131 +++++--- tests/Unit/Controller/FeedControllerTest.php | 144 +++++---- tests/Unit/Controller/FolderApiControllerTest.php | 77 +++-- tests/Unit/Controller/FolderControllerTest.php | 50 ++-- tests/Unit/Controller/ItemApiControllerTest.php | 179 +++++++---- tests/Unit/Controller/ItemControllerTest.php | 160 ++++++---- tests/Unit/Controller/JSONHttpErrorTest.php | 17 +- tests/Unit/Controller/PageControllerTest.php | 194 ++++++++---- tests/Unit/Controller/UserApiControllerTest.php | 56 ++-- tests/Unit/Controller/UtilityApiControllerTest.php | 44 ++- tests/Unit/Db/FeedTest.php | 41 ++- tests/Unit/Db/FolderMapperTest.php | 38 ++- tests/Unit/Db/FolderTest.php | 29 +- tests/Unit/Db/ItemTest.php | 99 +++--- tests/Unit/Db/MapperFactoryTest.php | 63 ++-- tests/Unit/Db/MapperTestUtility.php | 120 +++++--- tests/Unit/Fetcher/FeedFetcherTest.php | 132 +++++--- tests/Unit/Fetcher/FetcherTest.php | 71 +++-- tests/Unit/Fetcher/YoutubeFetcherTest.php | 20 +- tests/Unit/Http/TextDownloadResponseTest.php | 17 +- tests/Unit/Http/TextResponseTest.php | 23 +- tests/Unit/Migration/MigrateStatusFlagsTest.php | 29 +- tests/Unit/Service/FeedServiceTest.php | 266 +++++++++++------ tests/Unit/Service/FolderServiceTest.php | 68 +++-- tests/Unit/Service/ItemServiceTest.php | 239 +++++++++------ tests/Unit/Service/ServiceTest.php | 32 +- tests/Unit/Service/StatusServiceTest.php | 50 ++-- tests/Unit/Utility/OPMLExporterTest.php | 98 +++--- tests/Unit/Utility/ProxyConfigParserTest.php | 32 +- tests/Unit/Utility/UpdaterTest.php | 38 ++- tests/bootstrap.php | 2 +- 112 files changed, 3813 insertions(+), 2338 deletions(-) diff --git a/appinfo/app.php b/appinfo/app.php index 65c53725c..9ce7f366f 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -7,8 +7,8 @@ * * @author Alessandro Cosentino * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\AppInfo; diff --git a/appinfo/routes.php b/appinfo/routes.php index 1f1e19517..7bf843cb2 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -7,8 +7,8 @@ * * @author Alessandro Cosentino * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ return ['routes' => [ diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5abd0c5be..d633de743 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\AppInfo; @@ -40,9 +40,11 @@ use OCA\News\Explore\RecommendedSites; use OCA\News\Utility\ProxyConfigParser; -class Application extends App { +class Application extends App +{ - public function __construct(array $urlParams=[]) { + public function __construct(array $urlParams=[]) + { parent::__construct('news', $urlParams); // files @@ -60,192 +62,245 @@ class Application extends App { /** * App config parser */ - /** @noinspection PhpParamsInspection */ - $this->registerService(AppConfig::class, function($c) { - $config = new AppConfig( - $c->query(INavigationManager::class), - $c->query(IURLGenerator::class), - $c->query(IJobList::class) - ); - - $config->loadConfig($c->query('info')); - - return $config; - }); + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + AppConfig::class, function ($c) { + $config = new AppConfig( + $c->query(INavigationManager::class), + $c->query(IURLGenerator::class), + $c->query(IJobList::class) + ); + + $config->loadConfig($c->query('info')); + + return $config; + } + ); /** * Core */ - /** @noinspection PhpParamsInspection */ - $this->registerService('LoggerParameters', function($c) { - return ['app' => $c->query('AppName')]; - }); - - /** @noinspection PhpParamsInspection */ - $this->registerService('databaseType', function($c) { - return $c->query(IConfig::class)->getSystemValue('dbtype'); - }); - - /** @noinspection PhpParamsInspection */ - $this->registerService('ConfigView', function($c) { - $fs = $c->query(IRootFolder::class); - $path = 'news/config'; - if ($fs->nodeExists($path)) { - return $fs->get($path); - } else { - return $fs->newFolder($path); + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + 'LoggerParameters', function ($c) { + return ['app' => $c->query('AppName')]; } - }); - - - /** @noinspection PhpParamsInspection */ - $this->registerService(Config::class, function($c) { - $config = new Config( - $c->query('ConfigView'), - $c->query(ILogger::class), - $c->query('LoggerParameters') - ); - $config->read($c->query('configFile'), true); - return $config; - }); - - /** @noinspection PhpParamsInspection */ - $this->registerService(HTMLPurifier::class, function($c) { - $directory = $c->query(IConfig::class) - ->getSystemValue('datadirectory') . '/news/cache/purifier'; - - if(!is_dir($directory)) { - mkdir($directory, 0770, true); + ); + + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + 'databaseType', function ($c) { + return $c->query(IConfig::class)->getSystemValue('dbtype'); } + ); + + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + 'ConfigView', function ($c) { + $fs = $c->query(IRootFolder::class); + $path = 'news/config'; + if ($fs->nodeExists($path)) { + return $fs->get($path); + } else { + return $fs->newFolder($path); + } + } + ); - $config = HTMLPurifier_Config::createDefault(); - $config->set('HTML.ForbiddenAttributes', 'class'); - $config->set('Cache.SerializerPath', $directory); - $config->set('HTML.SafeIframe', true); - $config->set('URI.SafeIframeRegexp', - '%^https://(?:www\.)?(' . - 'youtube(?:-nocookie)?.com/embed/|' . - 'player.vimeo.com/video/|' . - 'vk.com/video_ext.php)%'); //allow YouTube and Vimeo - $def = $config->getHTMLDefinition(true); - $def->addAttribute('iframe', 'allowfullscreen', 'Bool'); - return new HTMLPurifier($config); - }); /** - * Fetchers - */ - /** @noinspection PhpParamsInspection */ - $this->registerService(PicoFeedConfig::class, function($c) { - // FIXME: move this into a separate class for testing? - $config = $c->query(Config::class); - $proxy = $c->query(ProxyConfigParser::class); - - // use chrome's user agent string since mod_security rules - // assume that only browsers can send user agent strings. This - // can lead to blocked feed updates like joomla.org - // For more information see - // https://www.atomicorp.com/wiki/index.php/WAF_309925 - $userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36' . - '(KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36'; + * @noinspection PhpParamsInspection +*/ + $this->registerService( + Config::class, function ($c) { + $config = new Config( + $c->query('ConfigView'), + $c->query(ILogger::class), + $c->query('LoggerParameters') + ); + $config->read($c->query('configFile'), true); + return $config; + } + ); - $pico = new PicoFeedConfig(); - $pico->setClientUserAgent($userAgent) - ->setClientTimeout($config->getFeedFetcherTimeout()) - ->setMaxRedirections($config->getMaxRedirects()) - ->setMaxBodySize($config->getMaxSize()) - ->setParserHashAlgo('md5'); - - // proxy settings - $proxySettings = $proxy->parse(); - $host = $proxySettings['host']; - $port = $proxySettings['port']; - $user = $proxySettings['user']; - $password = $proxySettings['password']; - - if ($host) { - $pico->setProxyHostname($host); - - if ($port) { - $pico->setProxyPort($port); + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + HTMLPurifier::class, function ($c) { + $directory = $c->query(IConfig::class) + ->getSystemValue('datadirectory') . '/news/cache/purifier'; + + if(!is_dir($directory)) { + mkdir($directory, 0770, true); } - } - if ($user) { - $pico->setProxyUsername($user) - ->setProxyPassword($password); + $config = HTMLPurifier_Config::createDefault(); + $config->set('HTML.ForbiddenAttributes', 'class'); + $config->set('Cache.SerializerPath', $directory); + $config->set('HTML.SafeIframe', true); + $config->set( + 'URI.SafeIframeRegexp', + '%^https://(?:www\.)?(' . + 'youtube(?:-nocookie)?.com/embed/|' . + 'player.vimeo.com/video/|' . + 'vk.com/video_ext.php)%' + ); //allow YouTube and Vimeo + $def = $config->getHTMLDefinition(true); + $def->addAttribute('iframe', 'allowfullscreen', 'Bool'); + return new HTMLPurifier($config); } + ); - return $pico; - }); + /** + * Fetchers + */ + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + PicoFeedConfig::class, function ($c) { + // FIXME: move this into a separate class for testing? + $config = $c->query(Config::class); + $proxy = $c->query(ProxyConfigParser::class); + + // use chrome's user agent string since mod_security rules + // assume that only browsers can send user agent strings. This + // can lead to blocked feed updates like joomla.org + // For more information see + // https://www.atomicorp.com/wiki/index.php/WAF_309925 + $userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36' . + '(KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36'; - $this->registerService(PicoFeedReader::class, function ($c) { - return new PicoFeedReader($c->query(PicoFeedConfig::class)); - }); + $pico = new PicoFeedConfig(); + $pico->setClientUserAgent($userAgent) + ->setClientTimeout($config->getFeedFetcherTimeout()) + ->setMaxRedirections($config->getMaxRedirects()) + ->setMaxBodySize($config->getMaxSize()) + ->setParserHashAlgo('md5'); + + // proxy settings + $proxySettings = $proxy->parse(); + $host = $proxySettings['host']; + $port = $proxySettings['port']; + $user = $proxySettings['user']; + $password = $proxySettings['password']; + + if ($host) { + $pico->setProxyHostname($host); + + if ($port) { + $pico->setProxyPort($port); + } + } - /** @noinspection PhpParamsInspection */ - $this->registerService(Fetcher::class, function($c) { - $fetcher = new Fetcher(); + if ($user) { + $pico->setProxyUsername($user) + ->setProxyPassword($password); + } - // register fetchers in order, the most generic fetcher should be - // the last one - $fetcher->registerFetcher($c->query(YoutubeFetcher::class)); - $fetcher->registerFetcher($c->query(FeedFetcher::class)); + return $pico; + } + ); - return $fetcher; - }); + $this->registerService( + PicoFeedReader::class, function ($c) { + return new PicoFeedReader($c->query(PicoFeedConfig::class)); + } + ); + + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + Fetcher::class, function ($c) { + $fetcher = new Fetcher(); + + // register fetchers in order, the most generic fetcher should be + // the last one + $fetcher->registerFetcher($c->query(YoutubeFetcher::class)); + $fetcher->registerFetcher($c->query(FeedFetcher::class)); + + return $fetcher; + } + ); } /** * Registers the content of a file under a key + * * @param string $key * @param string $file path relative to this file, __DIR__ will be prepended */ - private function registerFileContents($key, $file) { - /** @noinspection PhpParamsInspection */ - $this->registerService($key, function () use ($file) { - return file_get_contents(__DIR__ . '/' . $file); - }); + private function registerFileContents($key, $file) + { + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + $key, function () use ($file) { + return file_get_contents(__DIR__ . '/' . $file); + } + ); } /** * Shortcut for registering a service - * @param string $key + * + * @param string $key * @param closure $factory * @param boolean $shared */ - private function registerService($key, $factory, $shared=true) { + private function registerService($key, $factory, $shared=true) + { $this->getContainer()->registerService($key, $factory, $shared); } /** * Shortcut for registering a parameter + * * @param string $key - * @param mixed $value + * @param mixed $value */ - private function registerParameter($key, $value) { + private function registerParameter($key, $value) + { $this->getContainer()->registerParameter($key, $value); } /** * Register a class containing the app construction logic instead of the * inlining everything in this class to enhance testability - * @param string $key fully qualified class name + * + * @param string $key fully qualified class name * @param string $factory fully qualified factory class name */ - private function registerFactory($key, $factory) { - /** @noinspection PhpParamsInspection */ - $this->registerService($key, function ($c) use ($factory) { - return $c->query($factory)->build(); - }); + private function registerFactory($key, $factory) + { + /** + * @noinspection PhpParamsInspection +*/ + $this->registerService( + $key, function ($c) use ($factory) { + return $c->query($factory)->build(); + } + ); } /** * Register the additional config parameters found in the info.xml */ - public function registerConfig() { + public function registerConfig() + { $this->getContainer()->query(AppConfig::class)->registerAll(); } diff --git a/lib/Command/Updater/AfterUpdate.php b/lib/Command/Updater/AfterUpdate.php index 728d2a937..a9becf543 100644 --- a/lib/Command/Updater/AfterUpdate.php +++ b/lib/Command/Updater/AfterUpdate.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2016 */ @@ -19,21 +19,27 @@ use Symfony\Component\Console\Output\OutputInterface; use \OCA\News\Utility\Updater; -class AfterUpdate extends Command { +class AfterUpdate extends Command +{ private $updater; - public function __construct(Updater $updater) { + public function __construct(Updater $updater) + { parent::__construct(); $this->updater = $updater; } - protected function configure() { + protected function configure() + { $this->setName('news:updater:after-update') - ->setDescription('This is used to clean up the database. It ' . - 'removes old read articles which are not starred'); + ->setDescription( + 'This is used to clean up the database. It ' . + 'removes old read articles which are not starred' + ); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output) + { $this->updater->afterUpdate(); } diff --git a/lib/Command/Updater/AllFeeds.php b/lib/Command/Updater/AllFeeds.php index 838ce1404..8947c714e 100644 --- a/lib/Command/Updater/AllFeeds.php +++ b/lib/Command/Updater/AllFeeds.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2016 */ @@ -20,23 +20,29 @@ use Symfony\Component\Console\Output\OutputInterface; use OCA\News\Service\FeedService; -class AllFeeds extends Command { +class AllFeeds extends Command +{ private $feedService; - public function __construct(FeedService $feedService) { + public function __construct(FeedService $feedService) + { parent::__construct(); $this->feedService = $feedService; } - protected function configure() { + protected function configure() + { $json = '{"feeds": [{"id": 39, "userId": "john"}, // etc ]}'; $this->setName('news:updater:all-feeds') - ->setDescription('Prints a JSON string which contains all feed ' . - 'ids and user ids, e.g.: ' . $json); + ->setDescription( + 'Prints a JSON string which contains all feed ' . + 'ids and user ids, e.g.: ' . $json + ); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output) + { $feeds = $this->feedService->findAllFromAllUsers(); $result = ['feeds' => []]; diff --git a/lib/Command/Updater/BeforeUpdate.php b/lib/Command/Updater/BeforeUpdate.php index 9a384d95a..9d562d010 100644 --- a/lib/Command/Updater/BeforeUpdate.php +++ b/lib/Command/Updater/BeforeUpdate.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2016 */ @@ -19,22 +19,28 @@ use Symfony\Component\Console\Output\OutputInterface; use \OCA\News\Utility\Updater; -class BeforeUpdate extends Command { +class BeforeUpdate extends Command +{ private $updater; - public function __construct(Updater $updater) { + public function __construct(Updater $updater) + { parent::__construct(); $this->updater = $updater; } - protected function configure() { + protected function configure() + { $this->setName('news:updater:before-update') - ->setDescription('This is used to clean up the database. It ' . + ->setDescription( + 'This is used to clean up the database. It ' . 'deletes folders and feeds that are marked for ' . - 'deletion'); + 'deletion' + ); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output) + { $this->updater->beforeUpdate(); } diff --git a/lib/Command/Updater/UpdateFeed.php b/lib/Command/Updater/UpdateFeed.php index 44ac914be..b07cc3e4a 100644 --- a/lib/Command/Updater/UpdateFeed.php +++ b/lib/Command/Updater/UpdateFeed.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2016 */ @@ -21,15 +21,18 @@ use Symfony\Component\Console\Output\OutputInterface; use OCA\News\Service\FeedService; -class UpdateFeed extends Command { +class UpdateFeed extends Command +{ private $feedService; - public function __construct(FeedService $feedService) { + public function __construct(FeedService $feedService) + { parent::__construct(); $this->feedService = $feedService; } - protected function configure() { + protected function configure() + { $this->setName('news:updater:update-feed') ->addArgument( 'feed-id', @@ -44,15 +47,18 @@ class UpdateFeed extends Command { ->setDescription('Console API for updating a single user\'s feed'); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output) + { $feedId = $input->getArgument('feed-id'); $userId = $input->getArgument('user-id'); try { $this->feedService->update($feedId, $userId); } catch (Exception $e) { - $output->writeln('Could not update feed with id ' . $feedId . + $output->writeln( + 'Could not update feed with id ' . $feedId . ' and user ' . $userId . ': ' . $e->getMessage() . - ' '); + ' ' + ); } } diff --git a/lib/Config/Config.php b/lib/Config/Config.php index c8f5844c3..511582dbb 100644 --- a/lib/Config/Config.php +++ b/lib/Config/Config.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Config; @@ -17,7 +17,8 @@ use OCP\ILogger; use OCP\Files\Folder; -class Config { +class Config +{ private $fileSystem; private $autoPurgeMinimumInterval; // seconds, used to define how @@ -34,8 +35,9 @@ class Config { private $exploreUrl; public function __construct(Folder $fileSystem, - ILogger $logger, - $LoggerParameters) { + ILogger $logger, + $LoggerParameters + ) { $this->fileSystem = $fileSystem; $this->autoPurgeMinimumInterval = 60; $this->autoPurgeCount = 200; @@ -48,7 +50,8 @@ class Config { $this->loggerParams = $LoggerParameters; } - public function getAutoPurgeMinimumInterval() { + public function getAutoPurgeMinimumInterval() + { if ($this->autoPurgeMinimumInterval > 60) { return $this->autoPurgeMinimumInterval; } else { @@ -56,71 +59,85 @@ class Config { } } - public function getAutoPurgeCount() { + public function getAutoPurgeCount() + { return $this->autoPurgeCount; } - public function getMaxRedirects() { + public function getMaxRedirects() + { return $this->maxRedirects; } - public function getFeedFetcherTimeout() { + public function getFeedFetcherTimeout() + { return $this->feedFetcherTimeout; } - public function getUseCronUpdates() { + public function getUseCronUpdates() + { return $this->useCronUpdates; } - public function getMaxSize() { + public function getMaxSize() + { return $this->maxSize; } - public function getExploreUrl() { + public function getExploreUrl() + { return $this->exploreUrl; } - public function setAutoPurgeMinimumInterval($value) { + public function setAutoPurgeMinimumInterval($value) + { $this->autoPurgeMinimumInterval = $value; } - public function setAutoPurgeCount($value) { + public function setAutoPurgeCount($value) + { $this->autoPurgeCount = $value; } - public function setMaxRedirects($value) { + public function setMaxRedirects($value) + { $this->maxRedirects = $value; } - public function setFeedFetcherTimeout($value) { + public function setFeedFetcherTimeout($value) + { $this->feedFetcherTimeout = $value; } - public function setUseCronUpdates($value) { + public function setUseCronUpdates($value) + { $this->useCronUpdates = $value; } - public function setMaxSize($value) { + public function setMaxSize($value) + { $this->maxSize = $value; } - public function setExploreUrl($value) { + public function setExploreUrl($value) + { $this->exploreUrl = $value; } - public function read($configPath, $createIfNotExists=false) { + public function read($configPath, $createIfNotExists=false) + { if($createIfNotExists && !$this->fileSystem->nodeExists($configPath)) { $this->fileSystem->newFile($configPath); $this->write($configPath); @@ -145,7 +162,7 @@ class Config { } else { $this->logger->warning( 'Configuration value "' . $key . - '" does not exist. Ignored value.' , + '" does not exist. Ignored value.', $this->loggerParams ); } @@ -156,7 +173,8 @@ class Config { } - public function write($configPath) { + public function write($configPath) + { $ini = 'autoPurgeMinimumInterval = ' . $this->autoPurgeMinimumInterval . "\n" . diff --git a/lib/Config/DependencyException.php b/lib/Config/DependencyException.php index eb175d209..4a6a168e3 100644 --- a/lib/Config/DependencyException.php +++ b/lib/Config/DependencyException.php @@ -5,22 +5,25 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Config; -class DependencyException extends \Exception { +class DependencyException extends \Exception +{ /** * Constructor + * * @param string $msg the error message */ - public function __construct($msg){ + public function __construct($msg) + { parent::__construct($msg); } diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index e5cd55711..7feff907b 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -7,8 +7,9 @@ * * @author Alessandro Cosentino * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -20,68 +21,94 @@ use OCP\AppFramework\Controller; use OCA\News\Config\Config; use OCA\News\Service\ItemService; -class AdminController extends Controller { - - private $config; - private $configPath; - private $itemService; +/** + * Class AdminController + * + * @package OCA\News\Controller + */ +class AdminController extends Controller +{ + private $_config; + private $_configPath; + private $_itemService; - public function __construct($AppName, IRequest $request, Config $config, - ItemService $itemService, $configFile){ - parent::__construct($AppName, $request); - $this->config = $config; - $this->configPath = $configFile; - $this->itemService = $itemService; + /** + * AdminController constructor. + * + * @param string $appName The name of the app + * @param IRequest $request The request + * @param Config $config Config for nextcloud + * @param ItemService $itemService Service for items + * @param string $configFile Path to the config + */ + public function __construct($appName, IRequest $request, Config $config, + ItemService $itemService, $configFile + ) { + parent::__construct($appName, $request); + $this->_config = $config; + $this->_configPath = $configFile; + $this->_itemService = $itemService; } - // There are no checks for the index method since the output is rendered - // in admin/admin.php - public function index() { + /** + * Controller main entry. + * + * There are no checks for the index method since the output is + * rendered in admin/admin.php + * + * @return TemplateResponse + */ + public function index() + { $data = [ 'autoPurgeMinimumInterval' => - $this->config->getAutoPurgeMinimumInterval(), - 'autoPurgeCount' => $this->config->getAutoPurgeCount(), - 'maxRedirects' => $this->config->getMaxRedirects(), - 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), - 'useCronUpdates' => $this->config->getUseCronUpdates(), - 'maxSize' => $this->config->getMaxSize(), - 'exploreUrl' => $this->config->getExploreUrl(), + $this->_config->getAutoPurgeMinimumInterval(), + 'autoPurgeCount' => $this->_config->getAutoPurgeCount(), + 'maxRedirects' => $this->_config->getMaxRedirects(), + 'feedFetcherTimeout' => $this->_config->getFeedFetcherTimeout(), + 'useCronUpdates' => $this->_config->getUseCronUpdates(), + 'maxSize' => $this->_config->getMaxSize(), + 'exploreUrl' => $this->_config->getExploreUrl(), ]; return new TemplateResponse($this->appName, 'admin', $data, 'blank'); } /** - * @param int $autoPurgeMinimumInterval - * @param int $autoPurgeCount - * @param int $maxRedirects - * @param int $feedFetcherTimeout - * @param int $maxSize - * @param bool $useCronUpdates - * @param string $exploreUrl + * Update the app config. + * + * @param int $autoPurgeMinimumInterval New minimum interval for auto-purge + * @param int $autoPurgeCount New value of auto-purge count + * @param int $maxRedirects New value for max amount of redirects + * @param int $feedFetcherTimeout New timeout value for feed fetcher + * @param int $maxSize New max feed size + * @param bool $useCronUpdates Whether or not to use cron updates + * @param string $exploreUrl URL to use for the explore feed + * * @return array with the updated values */ public function update($autoPurgeMinimumInterval, $autoPurgeCount, - $maxRedirects, $feedFetcherTimeout, $maxSize, - $useCronUpdates, $exploreUrl) { - $this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval); - $this->config->setAutoPurgeCount($autoPurgeCount); - $this->config->setMaxRedirects($maxRedirects); - $this->config->setMaxSize($maxSize); - $this->config->setFeedFetcherTimeout($feedFetcherTimeout); - $this->config->setUseCronUpdates($useCronUpdates); - $this->config->setExploreUrl($exploreUrl); - $this->config->write($this->configPath); + $maxRedirects, $feedFetcherTimeout, $maxSize, + $useCronUpdates, $exploreUrl + ) { + $this->_config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval); + $this->_config->setAutoPurgeCount($autoPurgeCount); + $this->_config->setMaxRedirects($maxRedirects); + $this->_config->setMaxSize($maxSize); + $this->_config->setFeedFetcherTimeout($feedFetcherTimeout); + $this->_config->setUseCronUpdates($useCronUpdates); + $this->_config->setExploreUrl($exploreUrl); + $this->_config->write($this->_configPath); return [ 'autoPurgeMinimumInterval' => - $this->config->getAutoPurgeMinimumInterval(), - 'autoPurgeCount' => $this->config->getAutoPurgeCount(), - 'maxRedirects' => $this->config->getMaxRedirects(), - 'maxSize' => $this->config->getMaxSize(), - 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), - 'useCronUpdates' => $this->config->getUseCronUpdates(), - 'exploreUrl' => $this->config->getExploreUrl(), + $this->_config->getAutoPurgeMinimumInterval(), + 'autoPurgeCount' => $this->_config->getAutoPurgeCount(), + 'maxRedirects' => $this->_config->getMaxRedirects(), + 'maxSize' => $this->_config->getMaxSize(), + 'feedFetcherTimeout' => $this->_config->getFeedFetcherTimeout(), + 'useCronUpdates' => $this->_config->getUseCronUpdates(), + 'exploreUrl' => $this->_config->getExploreUrl(), ]; } diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index d16c6438d..f5052b49a 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -7,8 +7,8 @@ * * @author Alessandro Cosentino * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -16,19 +16,35 @@ namespace OCA\News\Controller; use OCP\IRequest; use OCP\AppFramework\ApiController as BaseApiController; -class ApiController extends BaseApiController { - - public function __construct($appName, - IRequest $request){ +/** + * Class ApiController + * + * @package OCA\News\Controller + */ +class ApiController extends BaseApiController +{ + /** + * ApiController constructor. + * + * @param string $appName The name of the app + * @param IRequest $request The request + */ + public function __construct($appName, IRequest $request) + { parent::__construct($appName, $request); } /** + * Indication of the API levels + * * @PublicPage * @NoCSRFRequired * @CORS + * + * @return array */ - public function index() { + public function index() + { return [ 'apiLevels' => ['v1-2'] ]; diff --git a/lib/Controller/EntityApiSerializer.php b/lib/Controller/EntityApiSerializer.php index af126045e..f624eb84c 100644 --- a/lib/Controller/EntityApiSerializer.php +++ b/lib/Controller/EntityApiSerializer.php @@ -5,8 +5,8 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2014 + * @author Bernhard Posselt + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -14,11 +14,13 @@ namespace OCA\News\Controller; use \OCA\News\Db\IAPI; -class EntityApiSerializer { +class EntityApiSerializer +{ private $level; - public function __construct($level) { + public function __construct($level) + { $this->level = $level; } @@ -26,14 +28,15 @@ class EntityApiSerializer { /** * Call toAPI() method on all entities. Works on * - * @param mixed $data : - * * Entity - * * Entity[] - * * array('level' => Entity[]) - * * Response + * @param mixed $data : + * * Entity + * * Entity[] + * * array('level' => Entity[]) + * * Response * @return array|mixed */ - public function serialize($data) { + public function serialize($data) + { if($data instanceof IAPI) { return [$this->level => [$data->toAPI()]]; @@ -49,14 +52,15 @@ class EntityApiSerializer { } - private function convert($entities) { + private function convert($entities) + { $converted = []; foreach($entities as $entity) { if($entity instanceof IAPI) { $converted[] = $entity->toAPI(); - // break if it contains anything else than entities + // break if it contains anything else than entities } else { return $entities; } diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php index 11060f075..1ce81963d 100644 --- a/lib/Controller/ExportController.php +++ b/lib/Controller/ExportController.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -24,7 +24,8 @@ use \OCA\News\Service\FeedService; use \OCA\News\Service\ItemService; use \OCA\News\Utility\OPMLExporter; -class ExportController extends Controller { +class ExportController extends Controller +{ private $opmlExporter; private $folderService; @@ -32,14 +33,15 @@ class ExportController extends Controller { private $itemService; private $userId; - public function __construct($AppName, - IRequest $request, - FolderService $folderService, - FeedService $feedService, - ItemService $itemService, - OPMLExporter $opmlExporter, - $UserId){ - parent::__construct($AppName, $request); + public function __construct($appName, + IRequest $request, + FolderService $folderService, + FeedService $feedService, + ItemService $itemService, + OPMLExporter $opmlExporter, + $UserId + ) { + parent::__construct($appName, $request); $this->feedService = $feedService; $this->folderService = $folderService; $this->opmlExporter = $opmlExporter; @@ -52,7 +54,8 @@ class ExportController extends Controller { * @NoAdminRequired * @NoCSRFRequired */ - public function opml(){ + public function opml() + { $feeds = $this->feedService->findAll($this->userId); $folders = $this->folderService->findAll($this->userId); $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); @@ -66,7 +69,8 @@ class ExportController extends Controller { * @NoAdminRequired * @NoCSRFRequired */ - public function articles(){ + public function articles() + { $feeds = $this->feedService->findAll($this->userId); $items = $this->itemService->getUnreadOrStarred($this->userId); @@ -82,8 +86,10 @@ class ExportController extends Controller { } $response = new JSONResponse($articles); - $response->addHeader('Content-Disposition', - 'attachment; filename="articles.json"'); + $response->addHeader( + 'Content-Disposition', + 'attachment; filename="articles.json"' + ); return $response; } diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index eb57198d8..344d72bd0 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -23,7 +23,8 @@ use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Service\ServiceConflictException; -class FeedApiController extends ApiController { +class FeedApiController extends ApiController +{ use JSONHttpError; @@ -34,14 +35,15 @@ class FeedApiController extends ApiController { private $loggerParams; private $serializer; - public function __construct($AppName, - IRequest $request, - FeedService $feedService, - ItemService $itemService, - ILogger $logger, - $UserId, - $LoggerParameters){ - parent::__construct($AppName, $request); + public function __construct($appName, + IRequest $request, + FeedService $feedService, + ItemService $itemService, + ILogger $logger, + $UserId, + $LoggerParameters + ) { + parent::__construct($appName, $request); $this->feedService = $feedService; $this->itemService = $itemService; $this->userId = $UserId; @@ -56,7 +58,8 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * @CORS */ - public function index() { + public function index() + { $result = [ 'starredCount' => $this->itemService->starredCount($this->userId), @@ -68,8 +71,9 @@ class FeedApiController extends ApiController { $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) {} + // in case there are no items, ignore + } catch(ServiceNotFoundException $ex) { + } return $this->serializer->serialize($result); } @@ -81,10 +85,11 @@ class FeedApiController extends ApiController { * @CORS * * @param string $url - * @param int $folderId + * @param int $folderId * @return array|mixed|\OCP\AppFramework\Http\JSONResponse */ - public function create($url, $folderId=0) { + public function create($url, $folderId=0) + { try { $this->feedService->purgeDeleted($this->userId, false); @@ -95,8 +100,9 @@ class FeedApiController extends ApiController { $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) {} + // in case there are no items, ignore + } catch(ServiceNotFoundException $ex) { + } return $this->serializer->serialize($result); @@ -116,7 +122,8 @@ class FeedApiController extends ApiController { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function delete($feedId) { + public function delete($feedId) + { try { $this->feedService->delete($feedId, $this->userId); } catch(ServiceNotFoundException $ex) { @@ -135,7 +142,8 @@ class FeedApiController extends ApiController { * @param int $feedId * @param int $newestItemId */ - public function read($feedId, $newestItemId) { + public function read($feedId, $newestItemId) + { $this->itemService->readFeed($feedId, $newestItemId, $this->userId); } @@ -149,7 +157,8 @@ class FeedApiController extends ApiController { * @param int $folderId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function move($feedId, $folderId) { + public function move($feedId, $folderId) + { try { $this->feedService->patch( $feedId, $this->userId, ['folderId' => $folderId] @@ -167,11 +176,12 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * @CORS * - * @param int $feedId + * @param int $feedId * @param string $feedTitle * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function rename($feedId, $feedTitle) { + public function rename($feedId, $feedTitle) + { try { $this->feedService->patch( $feedId, $this->userId, ['title' => $feedTitle] @@ -188,7 +198,8 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * @CORS */ - public function fromAllUsers() { + public function fromAllUsers() + { $feeds = $this->feedService->findAllFromAllUsers(); $result = ['feeds' => []]; @@ -207,15 +218,18 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * * @param string $userId - * @param int $feedId + * @param int $feedId */ - public function update($userId, $feedId) { + public function update($userId, $feedId) + { try { $this->feedService->update($feedId, $userId); - // ignore update failure + // ignore update failure } catch(\Exception $ex) { - $this->logger->debug('Could not update feed ' . $ex->getMessage(), - $this->loggerParams); + $this->logger->debug( + 'Could not update feed ' . $ex->getMessage(), + $this->loggerParams + ); } } diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index fecd58398..cf323b58e 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -26,7 +26,8 @@ use OCA\News\Service\ServiceConflictException; use OCA\News\Db\FeedType; -class FeedController extends Controller { +class FeedController extends Controller +{ use JSONHttpError; @@ -36,14 +37,15 @@ class FeedController extends Controller { private $userId; private $settings; - public function __construct($AppName, - IRequest $request, - FolderService $folderService, - FeedService $feedService, - ItemService $itemService, - IConfig $settings, - $UserId){ - parent::__construct($AppName, $request); + public function __construct($appName, + IRequest $request, + FolderService $folderService, + FeedService $feedService, + ItemService $itemService, + IConfig $settings, + $UserId + ) { + parent::__construct($appName, $request); $this->feedService = $feedService; $this->folderService = $folderService; $this->itemService = $itemService; @@ -55,7 +57,8 @@ class FeedController extends Controller { /** * @NoAdminRequired */ - public function index(){ + public function index() + { // this method is also used to update the interface // because of this we also pass the starred count and the newest @@ -69,9 +72,10 @@ class FeedController extends Controller { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // An exception occurs if there is a newest item. If there is none, - // simply ignore it and do not add the newestItemId - } catch (ServiceNotFoundException $ex) {} + // An exception occurs if there is a newest item. If there is none, + // simply ignore it and do not add the newestItemId + } catch (ServiceNotFoundException $ex) { + } return $params; } @@ -80,27 +84,32 @@ class FeedController extends Controller { /** * @NoAdminRequired */ - public function active(){ - $feedId = (int) $this->settings->getUserValue($this->userId, - $this->appName,'lastViewedFeedId'); - $feedType = $this->settings->getUserValue($this->userId, $this->appName, - 'lastViewedFeedType'); + public function active() + { + $feedId = (int) $this->settings->getUserValue( + $this->userId, + $this->appName, 'lastViewedFeedId' + ); + $feedType = $this->settings->getUserValue( + $this->userId, $this->appName, + 'lastViewedFeedType' + ); // cast from null to int is 0 - if($feedType !== null){ + if($feedType !== null) { $feedType = (int) $feedType; } // check if feed or folder exists try { - if($feedType === FeedType::FOLDER){ + if($feedType === FeedType::FOLDER) { $this->folderService->find($feedId, $this->userId); - } elseif ($feedType === FeedType::FEED){ + } elseif ($feedType === FeedType::FEED) { $this->feedService->find($feedId, $this->userId); - // if its the first launch, those values will be null - } elseif($feedType === null){ + // if its the first launch, those values will be null + } elseif($feedType === null) { throw new ServiceNotFoundException(''); } @@ -122,31 +131,35 @@ class FeedController extends Controller { * @NoAdminRequired * * @param string $url - * @param int $parentFolderId + * @param int $parentFolderId * @param string $title * @param string $user * @param string $password * @return array|\OCP\AppFramework\Http\JSONResponse */ public function create($url, $parentFolderId, $title=null, - $user=null, $password=null){ + $user=null, $password=null + ) { try { // we need to purge deleted feeds if a feed is created to // prevent already exists exceptions $this->feedService->purgeDeleted($this->userId, false); - $feed = $this->feedService->create($url, $parentFolderId, - $this->userId, $title, - $user, $password); + $feed = $this->feedService->create( + $url, $parentFolderId, + $this->userId, $title, + $user, $password + ); $params = ['feeds' => [$feed]]; try { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // An exception occurs if there is a newest item. If there is none, - // simply ignore it and do not add the newestItemId - } catch (ServiceNotFoundException $ex) {} + // An exception occurs if there is a newest item. If there is none, + // simply ignore it and do not add the newestItemId + } catch (ServiceNotFoundException $ex) { + } return $params; @@ -165,7 +178,8 @@ class FeedController extends Controller { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function delete($feedId){ + public function delete($feedId) + { try { $this->feedService->markDeleted($feedId, $this->userId); } catch(ServiceNotFoundException $ex) { @@ -182,7 +196,8 @@ class FeedController extends Controller { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function update($feedId){ + public function update($feedId) + { try { $feed = $this->feedService->update($feedId, $this->userId); @@ -210,7 +225,8 @@ class FeedController extends Controller { * @param array $json * @return array */ - public function import($json) { + public function import($json) + { $feed = $this->feedService->importArticles($json, $this->userId); $params = [ @@ -232,7 +248,8 @@ class FeedController extends Controller { * @param int $highestItemId * @return array */ - public function read($feedId, $highestItemId){ + public function read($feedId, $highestItemId) + { $this->itemService->readFeed($feedId, $highestItemId, $this->userId); return [ @@ -252,7 +269,8 @@ class FeedController extends Controller { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function restore($feedId){ + public function restore($feedId) + { try { $this->feedService->unmarkDeleted($feedId, $this->userId); } catch(ServiceNotFoundException $ex) { @@ -265,17 +283,18 @@ class FeedController extends Controller { /** * @NoAdminRequired * - * @param int $feedId - * @param bool $pinned - * @param bool $fullTextEnabled - * @param int $updateMode - * @param int $ordering - * @param int $folderId + * @param int $feedId + * @param bool $pinned + * @param bool $fullTextEnabled + * @param int $updateMode + * @param int $ordering + * @param int $folderId * @param string $title */ public function patch($feedId, $pinned=null, $fullTextEnabled=null, - $updateMode=null, $ordering=null, $title=null, - $folderId=null) { + $updateMode=null, $ordering=null, $title=null, + $folderId=null + ) { $attributes = [ 'pinned' => $pinned, 'fullTextEnabled' => $fullTextEnabled, @@ -285,9 +304,11 @@ class FeedController extends Controller { 'folderId' => $folderId ]; - $diff = array_filter($attributes, function ($value) { - return $value !== null; - }); + $diff = array_filter( + $attributes, function ($value) { + return $value !== null; + } + ); try { $this->feedService->patch($feedId, $this->userId, $diff); diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php index 88385b171..b24ae9acb 100644 --- a/lib/Controller/FolderApiController.php +++ b/lib/Controller/FolderApiController.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -23,7 +23,8 @@ use \OCA\News\Service\ServiceConflictException; use \OCA\News\Service\ServiceValidationException; -class FolderApiController extends ApiController { +class FolderApiController e