From becce6b7520912257c3d72697a3aefec9923a467 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Thu, 29 Nov 2018 20:59:46 +0100 Subject: Define an official codestyle and adhere to it. --- CONTRIBUTING.md | 22 +- Makefile | 6 + composer.json | 3 +- composer.lock | 359 +++++------------------------ docs/install.md | 4 +- lib/AppInfo/Application.php | 5 - lib/Command/Updater/AfterUpdate.php | 7 +- lib/Command/Updater/AllFeeds.php | 8 +- lib/Command/Updater/BeforeUpdate.php | 7 +- lib/Command/Updater/UpdateFeed.php | 8 +- lib/Config/Config.php | 52 ++--- lib/Config/DependencyException.php | 4 +- lib/Controller/AdminController.php | 76 +++--- lib/Controller/ApiController.php | 10 +- lib/Controller/EntityApiSerializer.php | 20 +- lib/Controller/ExportController.php | 13 +- lib/Controller/FeedApiController.php | 48 ++-- lib/Controller/FeedController.php | 73 +++--- lib/Controller/FolderApiController.php | 30 ++- lib/Controller/FolderController.php | 50 ++-- lib/Controller/ItemApiController.php | 80 ++++--- lib/Controller/ItemController.php | 82 ++++--- lib/Controller/JSONHttpError.php | 7 +- lib/Controller/PageController.php | 61 +++-- lib/Controller/UserApiController.php | 6 +- lib/Controller/UtilityApiController.php | 14 +- lib/Cron/Updater.php | 9 +- lib/Db/EntityJSONSerializer.php | 8 +- lib/Db/Feed.php | 1 - lib/Db/FeedMapper.php | 15 +- lib/Db/FeedType.php | 3 +- lib/Db/Folder.php | 1 - lib/Db/FolderMapper.php | 12 +- lib/Db/Item.php | 4 +- lib/Db/ItemMapper.php | 85 ++++--- lib/Db/MapperFactory.php | 16 +- lib/Db/Mysql/ItemMapper.php | 9 +- lib/Db/NewsMapper.php | 17 +- lib/DependencyInjection/IFactory.php | 1 - lib/Explore/RecommendedSites.php | 6 +- lib/Fetcher/FeedFetcher.php | 190 ++++++++------- lib/Fetcher/Fetcher.php | 53 +++-- lib/Fetcher/FetcherException.php | 3 +- lib/Fetcher/IFeedFetcher.php | 46 ++-- lib/Fetcher/YoutubeFetcher.php | 52 ++--- lib/Hooks/User.php | 3 +- lib/Http/TextDownloadResponse.php | 3 - lib/Http/TextResponse.php | 4 +- lib/Migration/MigrateStatusFlags.php | 12 +- lib/Plugin/Client/Plugin.php | 11 +- lib/PostProcessor/LWNProcessor.php | 19 +- lib/Service/FeedService.php | 86 ++++--- lib/Service/FolderService.php | 23 +- lib/Service/ItemService.php | 122 ++++++---- lib/Service/Service.php | 6 +- lib/Service/ServiceConflictException.php | 4 +- lib/Service/ServiceException.php | 4 +- lib/Service/ServiceNotFoundException.php | 4 +- lib/Service/ServiceValidationException.php | 4 +- lib/Service/StatusService.php | 19 +- lib/Settings/Admin.php | 8 +- lib/Settings/Section.php | 12 +- lib/Utility/OPMLExporter.php | 5 +- lib/Utility/PicoFeedClientFactory.php | 8 +- lib/Utility/PicoFeedFaviconFactory.php | 8 +- lib/Utility/ProxyConfigParser.php | 9 +- lib/Utility/Time.php | 5 +- lib/Utility/Updater.php | 14 +- 68 files changed, 899 insertions(+), 1080 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e14b07828..5f591330e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,8 @@ # Contributing Read this when you want to: -* file an issue (bug or feature request) -* help translate the News file to your language +* [file an issue (bug or feature request)](#Issues) +* [help translate the News file to your language](#Translation) * start programming and change the way the News app works * add cool new feeds to the feed explore section * want to provide additional full text feed rules @@ -119,16 +119,8 @@ We usually hang out on **irc.freenode.net** in the **#nextcloud-news** and **#ne ### Coding Style Guidelines -* Use 4 spaces for indention. Why spaces? Because it looks the same on every machine and on the web where you can't normally control the tab width. -* Place the open curly braces on the same line as the parameter block, e.g.: - ```php - if (condition) { - // code - } else { - // code - } - ``` - -* Place a space before and after the parameter block for if, else, for, foreach, function -* Everything should be in camelCase except classes which should be in PascalCase -* For linting JavaScript, a [jshint file](https://github.com/nextcloud/news/blob/master/js/.jshintrc) is used that is run before compiling the JavaScript +The PHP code should all adhere to [PSR-2](https://www.php-fig.org/psr/psr-2/). +*Note that this is a different codestyle than nextcloud itself uses.* +To test the codestyle you can run `make phpcs`. + +For linting JavaScript, a [jshint file](https://github.com/nextcloud/news/blob/master/js/.jshintrc) is used that is run before compiling the JavaScript diff --git a/Makefile b/Makefile index 048848014..d716d09da 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,11 @@ endif clean: rm -rf ./build +# Reports PHP codestyle violations +.PHONY: phpcs +phpcs: + ./vendor/bin/phpcs --standard=PSR2 lib + # Same as clean but also removes dependencies installed by composer and # npm .PHONY: distclean @@ -183,3 +188,4 @@ test: ./vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-clover build/php-unit.clover # \Test\TestCase is only allowed to access the db if TRAVIS environment variable is set env TRAVIS=1 ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml --coverage-clover build/php-unit.clover + $(MAKE) phpcs diff --git a/composer.json b/composer.json index efe82796e..4a03b86a2 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "nicolus/picofeed": "0.1.35" }, "require-dev": { - "phpunit/phpunit": "^6.5" + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3.3" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 441af16c8..2c814bcd0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ac4e6dcfaee8b83840050366cacebc4c", + "content-hash": "f4a0d96b7e83ec4d9d232412b9e61566", "packages": [ { "name": "ezyang/htmlpurifier", @@ -322,262 +322,6 @@ ], "time": "2017-07-22T11:58:36+00:00" }, - { - "name": "guzzlehttp/guzzle", - "version": "6.3.3", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "shasum": "" - }, - "require": { - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", - "php": ">=5.5" - }, - "require-dev": { - "ext-curl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" - }, - "suggest": { - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.3-dev" - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "rest", - "web service" - ], - "time": "2018-04-22T15:46:56+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "time": "2016-12-20T10:07:11+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "1.4.2", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "request", - "response", - "stream", - "uri", - "url" - ], - "time": "2017-03-20T17:10:46+00:00" - }, - { - "name": "kevinrob/guzzle-cache-middleware", - "version": "v2.1.1", - "source": { - "type": "git", - "url": "https://github.com/Kevinrob/guzzle-cache-middleware.git", - "reference": "6952064f7747756b0be7b4c234c0fd7535ea4c8c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Kevinrob/guzzle-cache-middleware/zipball/6952064f7747756b0be7b4c234c0fd7535ea4c8c", - "reference": "6952064f7747756b0be7b4c234c0fd7535ea4c8c", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "cache/array-adapter": "^0.4", - "doctrine/cache": "^1.0", - "guzzlehttp/guzzle": "^6.0", - "illuminate/cache": "^5.0", - "league/flysystem": "^1.0", - "phpunit/phpunit": "^4.0 || ^5.0", - "psr/cache": "^1.0" - }, - "suggest": { - "doctrine/cache": "This library have a lot of ready-to-use cache storage (to be use with Kevinrob\\GuzzleCache\\Storage\\DoctrineCacheStorage)", - "guzzlehttp/guzzle": "For using this library. It was created for Guzzle6. (but you can use it with any PSR-7 HTTP Client)", - "laravel/framework": "To be use with Kevinrob\\GuzzleCache\\Storage\\LaravelCacheStorage", - "league/flysystem": "To be use with Kevinrob\\GuzzleCache\\Storage\\FlysystemStorage", - "psr/cache": "To be use with Kevinrob\\GuzzleCache\\Storage\\Psr6CacheStorage" - }, - "type": "library", - "autoload": { - "psr-4": { - "Kevinrob\\GuzzleCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kevin Robatel", - "email": "kevinrob2@gmail.com", - "homepage": "https://github.com/Kevinrob" - } - ], - "description": "A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)", - "homepage": "https://github.com/Kevinrob/guzzle-cache-middleware", - "keywords": [ - "Etag", - "Flysystem", - "Guzzle", - "cache", - "cache-control", - "doctrine", - "expiration", - "guzzle6", - "handler", - "http", - "http 1.1", - "middleware", - "performance", - "php", - "promise", - "psr6", - "psr7", - "rfc7234", - "validation" - ], - "time": "2017-08-17T12:23:43+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.8.1", @@ -1335,56 +1079,6 @@ ], "time": "2018-08-09T05:50:03+00:00" }, - { - "name": "psr/http-message", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "time": "2016-08-06T14:39:51+00:00" - }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", @@ -1944,6 +1638,57 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2018-09-23T23:08:17+00:00" + }, { "name": "theseer/tokenizer", "version": "1.1.0", diff --git a/docs/install.md b/docs/install.md index db6d38c05..4eaf3aa9c 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,8 +1,8 @@ # Installation/Update ## Dependencies -* PHP >= 5.6 -* Nextcloud 12 +* PHP >= 7.0 +* Nextcloud 14 * libxml >= 2.7.8 (2.9 recommended) * php-curl * iconv diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 9394e790b..d88bbbaec 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -31,7 +31,6 @@ use OCP\ILogger; use PicoFeed\Config\Config as PicoFeedConfig; use PicoFeed\Reader\Reader as PicoFeedReader; - class Application extends App { @@ -80,7 +79,6 @@ class Application extends App } }); - $container->registerService(Config::class, function (IContainer $c): Config { $config = new Config( $c->query('ConfigView'), @@ -168,8 +166,5 @@ class Application extends App return $fetcher; }); - - } - } diff --git a/lib/Command/Updater/AfterUpdate.php b/lib/Command/Updater/AfterUpdate.php index a9becf543..c80913fab 100644 --- a/lib/Command/Updater/AfterUpdate.php +++ b/lib/Command/Updater/AfterUpdate.php @@ -23,13 +23,13 @@ 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( @@ -38,9 +38,8 @@ class AfterUpdate extends Command ); } - 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 8947c714e..21471379d 100644 --- a/lib/Command/Updater/AllFeeds.php +++ b/lib/Command/Updater/AllFeeds.php @@ -19,18 +19,17 @@ use Symfony\Component\Console\Output\OutputInterface; use OCA\News\Service\FeedService; - 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 ]}'; @@ -41,7 +40,7 @@ class AllFeeds extends Command ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output) { $feeds = $this->feedService->findAllFromAllUsers(); $result = ['feeds' => []]; @@ -55,5 +54,4 @@ class AllFeeds extends Command print(json_encode($result)); } - } diff --git a/lib/Command/Updater/BeforeUpdate.php b/lib/Command/Updater/BeforeUpdate.php index 9d562d010..3a0b1ca72 100644 --- a/lib/Command/Updater/BeforeUpdate.php +++ b/lib/Command/Updater/BeforeUpdate.php @@ -23,13 +23,13 @@ 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( @@ -39,9 +39,8 @@ class BeforeUpdate extends Command ); } - 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 b07cc3e4a..f5cda22ad 100644 --- a/lib/Command/Updater/UpdateFeed.php +++ b/lib/Command/Updater/UpdateFeed.php @@ -20,18 +20,17 @@ use Symfony\Component\Console\Output\OutputInterface; use OCA\News\Service\FeedService; - 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( @@ -47,7 +46,7 @@ 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'); @@ -61,5 +60,4 @@ class UpdateFeed extends Command ); } } - } diff --git a/lib/Config/Config.php b/lib/Config/Config.php index 511582dbb..7c5cee74a 100644 --- a/lib/Config/Config.php +++ b/lib/Config/Config.php @@ -16,7 +16,6 @@ namespace OCA\News\Config; use OCP\ILogger; use OCP\Files\Folder; - class Config { @@ -34,7 +33,8 @@ class Config private $maxSize; private $exploreUrl; - public function __construct(Folder $fileSystem, + public function __construct( + Folder $fileSystem, ILogger $logger, $LoggerParameters ) { @@ -42,7 +42,7 @@ class Config $this->autoPurgeMinimumInterval = 60; $this->autoPurgeCount = 200; $this->maxRedirects = 10; - $this->maxSize = 100*1024*1024; // 100Mb + $this->maxSize = 100 * 1024 * 1024; // 100Mb $this->feedFetcherTimeout = 60; $this->useCronUpdates = true; $this->logger = $logger; @@ -50,7 +50,7 @@ class Config $this->loggerParams = $LoggerParameters; } - public function getAutoPurgeMinimumInterval() + public function getAutoPurgeMinimumInterval() { if ($this->autoPurgeMinimumInterval > 60) { return $this->autoPurgeMinimumInterval; @@ -59,103 +59,100 @@ 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)) { + if ($createIfNotExists && !$this->fileSystem->nodeExists($configPath)) { $this->fileSystem->newFile($configPath); $this->write($configPath); - } else { - $content = $this->fileSystem->get($configPath)->getContent(); $configValues = parse_ini_string($content); - if($configValues === false || count($configValues) === 0) { + if ($configValues === false || count($configValues) === 0) { $this->logger->warning( 'Configuration invalid. Ignoring values.', $this->loggerParams ); } else { - - foreach($configValues as $key => $value) { - if(property_exists($this, $key)) { + foreach ($configValues as $key => $value) { + if (property_exists($this, $key)) { $type = gettype($this->$key); settype($value, $type); $this->$key = $value; @@ -167,13 +164,12 @@ class Config ); } } - } } } - public function write($configPath) + public function write($configPath) { $ini = 'autoPurgeMinimumInterval = ' . @@ -194,6 +190,4 @@ class Config $this->fileSystem->get($configPath)->putContent($ini); } - - } diff --git a/lib/Config/DependencyException.php b/lib/Config/DependencyException.php index 4a6a168e3..6f9d21be6 100644 --- a/lib/Config/DependencyException.php +++ b/lib/Config/DependencyException.php @@ -26,6 +26,4 @@ class DependencyException extends \Exception { parent::__construct($msg); } - - -} \ No newline at end of file +} diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index 7feff907b..3ce09a0d1 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -28,9 +28,9 @@ use OCA\News\Service\ItemService; */ class AdminController extends Controller { - private $_config; - private $_configPath; - private $_itemService; + private $config; + private $configPath; + private $itemService; /** * AdminController constructor. @@ -41,13 +41,17 @@ class AdminController extends Controller * @param ItemService $itemService Service for items * @param string $configFile Path to the config */ - public function __construct($appName, IRequest $request, Config $config, - ItemService $itemService, $configFile + public function __construct( + $appName, + IRequest $request, + Config $config, + ItemService $itemService, + $configFile ) { parent::__construct($appName, $request); - $this->_config = $config; - $this->_configPath = $configFile; - $this->_itemService = $itemService; + $this->config = $config; + $this->configPath = $configFile; + $this->itemService = $itemService; } /** @@ -62,13 +66,13 @@ class AdminController extends Controller { $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'); } @@ -87,29 +91,33 @@ class AdminController extends Controller * * @return array with the updated values */ - public function update($autoPurgeMinimumInterval, $autoPurgeCount, - $maxRedirects, $feedFetcherTimeout, $maxSize, - $useCronUpdates, $exploreUrl + 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); + $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 d2a787a28..68caf9236 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -40,7 +40,8 @@ class ApiController extends BaseApiController * @param IRequest $request The request * @param IUserSession $userSession The user session */ - public function __construct($appName, IRequest $request, IUserSession $userSession) { + public function __construct($appName, IRequest $request, IUserSession $userSession) + { parent::__construct($appName, $request); $this->userSession = $userSession; } @@ -48,14 +49,16 @@ class ApiController extends BaseApiController /** * @return IUser */ - protected function getUser() { + protected function getUser() + { return $this->userSession->getUser(); } /** * @return string */ - protected function getUserId() { + protected function getUserId() + { return $this->getUser()->getUID(); } @@ -74,5 +77,4 @@ class ApiController extends BaseApiController 'apiLevels' => ['v1-2'] ]; } - } diff --git a/lib/Controller/EntityApiSerializer.php b/lib/Controller/EntityApiSerializer.php index f624eb84c..78a9b1031 100644 --- a/lib/Controller/EntityApiSerializer.php +++ b/lib/Controller/EntityApiSerializer.php @@ -13,13 +13,12 @@ namespace OCA\News\Controller; use \OCA\News\Db\IAPI; - class EntityApiSerializer { private $level; - public function __construct($level) + public function __construct($level) { $this->level = $level; } @@ -35,16 +34,16 @@ class EntityApiSerializer * * Response * @return array|mixed */ - public function serialize($data) + public function serialize($data) { - if($data instanceof IAPI) { + if ($data instanceof IAPI) { return [$this->level => [$data->toAPI()]]; } - if(is_array($data) && array_key_exists($this->level, $data)) { + if (is_array($data) && array_key_exists($this->level, $data)) { $data[$this->level] = $this->convert($data[$this->level]); - } elseif(is_array($data)) { + } elseif (is_array($data)) { $data = [$this->level => $this->convert($data)]; } @@ -52,12 +51,12 @@ class EntityApiSerializer } - private function convert($entities) + private function convert($entities) { $converted = []; - foreach($entities as $entity) { - if($entity instanceof IAPI) { + foreach ($entities as $entity) { + if ($entity instanceof IAPI) { $converted[] = $entity->toAPI(); // break if it contains anything else than entities @@ -68,5 +67,4 @@ class EntityApiSerializer return $converted; } - -} \ No newline at end of file +} diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php index 07ce06f45..16bdfbd4e 100644 --- a/lib/Controller/ExportController.php +++ b/lib/Controller/ExportController.php @@ -33,7 +33,8 @@ class ExportController extends Controller private $itemService; private $userId; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, FolderService $folderService, FeedService $feedService, @@ -60,7 +61,7 @@ class ExportController extends Controller $folders = $this->folderService->findAll($this->userId); $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); $date = date('Y-m-d'); - $name = "subscriptions-".$date.".opml"; + $name = "subscriptions-" . $date . ".opml"; $mimeType = 'text/xml'; return new TextDownloadResponse($opml, $name, $mimeType); } @@ -77,12 +78,12 @@ class ExportController extends Controller // build assoc array for fast access $feedsDict = []; - foreach($feeds as $feed) { + foreach ($feeds as $feed) { $feedsDict['feed' . $feed->getId()] = $feed; } $articles = []; - foreach($items as $item) { + foreach ($items as $item) { $articles[] = $item->toExport($feedsDict); } @@ -93,6 +94,4 @@ class ExportController extends Controller ); return $response; } - - -} \ No newline at end of file +} diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index 2e4a85eef..160a8bcd6 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -25,10 +25,8 @@ use \OCA\News\Service\ItemService; use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Service\ServiceConflictException; - class FeedApiController extends ApiController { - use JSONHttpError; private $itemService; @@ -37,7 +35,8 @@ class FeedApiController extends ApiController private $loggerParams; private $serializer; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, IUserSession $userSession, FeedService $feedService, @@ -59,7 +58,7 @@ class FeedApiController extends ApiController * @NoCSRFRequired * @CORS */ - public function index() + public function index() { $result = [ @@ -73,7 +72,7 @@ class FeedApiController extends ApiController $this->itemService->getNewestItemId($this->getUserId()); // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { } return $this->serializer->serialize($result); @@ -89,7 +88,7 @@ class FeedApiController extends ApiController * @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->getUserId(), false); @@ -102,14 +101,13 @@ class FeedApiController extends ApiController $this->itemService->getNewestItemId($this->getUserId()); // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { } return $this->serializer->serialize($result); - - } catch(ServiceConflictException $ex) { + } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -123,11 +121,11 @@ 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->getUserId()); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -143,7 +141,7 @@ 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->getUserId()); } @@ -158,13 +156,15 @@ 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->getUserId(), ['folderId' => $folderId] + $feedId, + $this->getUserId(), + ['folderId' => $folderId] ); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -181,13 +181,15 @@ class FeedApiController extends ApiController * @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->getUserId(), ['title' => $feedTitle] + $feedId, + $this->getUserId(), + ['title' => $feedTitle] ); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -199,7 +201,7 @@ class FeedApiController extends ApiController * @NoCSRFRequired * @CORS */ - public function fromAllUsers() + public function fromAllUsers() { $feeds = $this->feedService->findAllFromAllUsers(); $result = ['feeds' => []]; @@ -221,18 +223,16 @@ class FeedApiController extends ApiController * @param string $userId * @param int $feedId */ - public function update($userId, $feedId) + public function update($userId, $feedId) { try { $this->feedService->update($feedId, $userId); // ignore update failure - } catch(\Exception $ex) { + } catch (\Exception $ex) { $this->logger->debug( 'Could not update feed ' . $ex->getMessage(), $this->loggerParams ); } } - - } diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index cf323b58e..dbb36bb02 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -25,10 +25,8 @@ use OCA\News\Service\ServiceNotFoundException; use OCA\News\Service\ServiceConflictException; use OCA\News\Db\FeedType; - class FeedController extends Controller { - use JSONHttpError; private $feedService; @@ -37,7 +35,8 @@ class FeedController extends Controller private $userId; private $settings; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, FolderService $folderService, FeedService $feedService, @@ -88,32 +87,32 @@ class FeedController extends Controller { $feedId = (int) $this->settings->getUserValue( $this->userId, - $this->appName, 'lastViewedFeedId' + $this->appName, + 'lastViewedFeedId' ); $feedType = $this->settings->getUserValue( - $this->userId, $this->appName, + $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) { $this->feedService->find($feedId, $this->userId); // if its the first launch, those values will be null - } elseif($feedType === null) { + } elseif ($feedType === null) { throw new ServiceNotFoundException(''); } - - } catch (ServiceNotFoundException $ex){ + } catch (ServiceNotFoundException $ex) { $feedId = 0; $feedType = FeedType::SUBSCRIPTIONS; } @@ -137,8 +136,12 @@ class FeedController extends Controller * @param string $password * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function create($url, $parentFolderId, $title=null, - $user=null, $password=null + public function create( + $url, + $parentFolderId, + $title = null, + $user = null, + $password = null ) { try { // we need to purge deleted feeds if a feed is created to @@ -146,9 +149,12 @@ class FeedController extends Controller $this->feedService->purgeDeleted($this->userId, false); $feed = $this->feedService->create( - $url, $parentFolderId, - $this->userId, $title, - $user, $password + $url, + $parentFolderId, + $this->userId, + $title, + $user, + $password ); $params = ['feeds' => [$feed]]; @@ -162,13 +168,11 @@ class FeedController extends Controller } return $params; - - } catch(ServiceConflictException $ex) { + } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } - } @@ -182,7 +186,7 @@ class FeedController extends Controller { try { $this->feedService->markDeleted($feedId, $this->userId); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -211,11 +215,9 @@ class FeedController extends Controller ] ] ]; - - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } - } @@ -225,7 +227,7 @@ class FeedController extends Controller * @param array $json * @return array */ - public function import($json) + public function import($json) { $feed = $this->feedService->importArticles($json, $this->userId); @@ -233,7 +235,7 @@ class FeedController extends Controller 'starred' => $this->itemService->starredCount($this->userId) ]; - if($feed) { + if ($feed) { $params['feeds'] = [$feed]; } @@ -273,7 +275,7 @@ class FeedController extends Controller { try { $this->feedService->unmarkDeleted($feedId, $this->userId); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -291,9 +293,14 @@ class FeedController extends Controller * @param int $folderId * @param string $title */ - public function patch($feedId, $pinned=null, $fullTextEnabled=null, - $updateMode=null, $ordering=null, $title=null, - $folderId=null + public function patch( + $feedId, + $pinned = null, + $fullTextEnabled = null, + $updateMode = null, + $ordering = null, + $title = null, + $folderId = null ) { $attributes = [ 'pinned' => $pinned, @@ -305,18 +312,18 @@ class FeedController extends Controller ]; $diff = array_filter( - $attributes, function ($value) { + $attributes, + function ($value) { return $value !== null; } ); try { $this->feedService->patch($feedId, $this->userId, $diff); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } return []; } - } diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php index 348fefda6..eb98b8107 100644 --- a/lib/Controller/FolderApiController.php +++ b/lib/Controller/FolderApiController.php @@ -25,17 +25,16 @@ use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Service\ServiceConflictException; use \OCA\News\Service\ServiceValidationException; - class FolderApiController extends ApiController { - use JSONHttpError; private $folderService; private $itemService; private $serializer; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, IUserSession $userSession, FolderService $folderService, @@ -53,7 +52,7 @@ class FolderApiController extends ApiController * @NoCSRFRequired * @CORS */ - public function index() + public function index() { return $this->serializer->serialize( $this->folderService->findAll($this->getUserId()) @@ -69,16 +68,16 @@ class FolderApiController extends ApiController * @param string $name * @return array|mixed|\OCP\AppFramework\Http\JSONResponse */ - public function create($name) + public function create($name) { try { $this->folderService->purgeDeleted($this->getUserId(), false); return $this->serializer->serialize( $this->folderService->create($name, $this->getUserId()) ); - } catch(ServiceValidationException $ex) { + } catch (ServiceValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); - } catch(ServiceConflictException $ex) { + } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); } } @@ -92,11 +91,11 @@ class FolderApiController extends ApiController * @param int $folderId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function delete($folderId) + public function delete($folderId) { try { $this->folderService->delete($folderId, $this->getUserId()); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -112,16 +111,15 @@ class FolderApiController extends ApiController * @param string $name * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function update($folderId, $name) + public function update($folderId, $name) { try { $this->folderService->rename($folderId, $name, $this->getUserId()); - - } catch(ServiceValidationException $ex) { + } catch (ServiceValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); - } catch(ServiceConflictException $ex) { + } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -137,10 +135,8 @@ class FolderApiController extends ApiController * @param int $folderId * @param int $newestItemId */ - public function read($folderId, $newestItemId) + public function read($folderId, $newestItemId) { $this->itemService->readFolder($folderId, $newestItemId, $this->getUserId()); } - - } diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index 8b4dadcca..d3089178d 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -24,10 +24,8 @@ use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Service\ServiceConflictException; use \OCA\News\Service\ServiceValidationException; - class FolderController extends Controller { - use JSONHttpError; private $folderService; @@ -35,7 +33,8 @@ class FolderController extends Controller private $itemService; private $userId; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, FolderService $folderService, FeedService $feedService, @@ -53,7 +52,7 @@ class FolderController extends Controller /** * @NoAdminRequired */ - public function index() + public function index() { $folders = $this->folderService->findAll($this->userId); return ['folders' => $folders]; @@ -67,11 +66,11 @@ class FolderController extends Controller * @param bool $open * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function open($folderId, $open) + public function open($folderId, $open) { try { $this->folderService->open($folderId, $open, $this->userId); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -85,7 +84,7 @@ class FolderController extends Controller * @param string $folderName * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function create($folderName) + public function create($folderName) { try { // we need to purge deleted folders if a folder is created to @@ -94,13 +93,11 @@ class FolderController extends Controller $folder = $this->folderService->create($folderName, $this->userId); return ['folders' => [$folder]]; - - } catch(ServiceConflictException $ex) { + } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceValidationException $ex) { + } catch (ServiceValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } - } @@ -110,11 +107,11 @@ class FolderController extends Controller * @param int $folderId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function delete($folderId) + public function delete($folderId) { try { $this->folderService->markDeleted($folderId, $this->userId); - } catch (ServiceNotFoundException $ex){ + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -129,24 +126,23 @@ class FolderController extends Controller * @param int $folderId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function rename($folderName, $folderId) + public function rename($folderName, $folderId) { try { $folder = $this->folderService->rename( - $folderId, $folderName, + $folderId, + $folderName, $this->userId ); return ['folders' => [$folder]]; - - } catch(ServiceConflictException $ex) { + } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceValidationException $ex) { + } catch (ServiceValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); - } catch (ServiceNotFoundException $ex){ + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } - } /** @@ -156,10 +152,12 @@ class FolderController extends Controller * @param int $highestItemId * @return array */ - public function read($folderId, $highestItemId) + public function read($folderId, $highestItemId) { $this->itemService->readFolder( - $folderId, $highestItemId, $this->userId + $folderId, + $highestItemId, + $this->userId ); return ['feeds' => $this->feedService->findAll($this->userId)]; @@ -172,16 +170,14 @@ class FolderController extends Controller * @param int $folderId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function restore($folderId) + public function restore($folderId) { try { $this->folderService->unmarkDeleted($folderId, $this->userId); - } catch (ServiceNotFoundException $ex){ + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } return []; } - - -} \ No newline at end of file +} diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index 601a3b409..cf4c7c730 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -24,13 +24,13 @@ use \OCA\News\Service\ServiceNotFoundException; class ItemApiController extends ApiController { - use JSONHttpError; private $itemService; private $serializer; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, IUserSession $userSession, ItemService $itemService @@ -54,12 +54,22 @@ class ItemApiController extends ApiController * @param bool $oldestFirst * @return array|mixed */ - public function index($type=3, $id=0, $getRead=true, $batchSize=-1, - $offset=0, $oldestFirst=false + public function index( + $type = 3, + $id = 0, + $getRead = true, + $batchSize = -1, + $offset = 0, + $oldestFirst = false ) { return $this->serializer->serialize( $this->itemService->findAll( - $id, $type, $batchSize, $offset, $getRead, $oldestFirst, + $id, + $type, + $batchSize, + $offset, + $getRead, + $oldestFirst, $this->getUserId() ) ); @@ -76,7 +86,7 @@ class ItemApiController extends ApiController * @param int $lastModified * @return array|mixed */ - public function updated($type=3, $id=0, $lastModified=0) + public function updated($type = 3, $id = 0, $lastModified = 0) { // needs to be turned into a millisecond timestamp to work properly if (strlen((string) $lastModified) <= 10) { @@ -86,18 +96,21 @@ class ItemApiController extends ApiController } return $this->serializer->serialize( $this->itemService->findAllNew( - $id, $type, $paddedLastModified, - true, $this->getUserId() + $id, + $type, + $paddedLastModified, + true, + $this->getUserId() ) ); } - private function setRead($isRead, $itemId) + private function setRead($isRead, $itemId) { try { $this->itemService->read($itemId, $isRead, $this->getUserId()); - } catch(ServiceNotFoundException $ex){ + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -113,7 +126,7 @@ class ItemApiController extends ApiController * @param int $itemId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function read($itemId) + public function read($itemId) { return $this->setRead(true, $itemId); } @@ -127,19 +140,22 @@ class ItemApiController extends ApiController * @param int $itemId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function unread($itemId) + public function unread($itemId) { return $this->setRead(false, $itemId); } - private function setStarred($isStarred, $feedId, $guidHash) + private function setStarred($isStarred, $feedId, $guidHash) { try { $this->itemService->star( - $feedId, $guidHash, $isStarred, $this->getUserId() + $feedId, + $guidHash, + $isStarred, + $this->getUserId() ); - } catch(ServiceNotFoundException $ex){ + } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -156,7 +172,7 @@ class ItemApiController extends ApiController * @param string $guidHash * @return array|\OCP\AppFramework\Http\JSONResponse