From 25af5bdf544f6264d42425765e4d60f3bdf6b914 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 10 Nov 2024 13:18:53 +0100 Subject: [PATCH] feat: :technologist: add rector --- composer.json | 6 +- composer.lock | 133 ++++++++++++++++-- lib/AppInfo/Application.php | 3 +- lib/Controller/EpisodesController.php | 4 +- lib/Controller/OpmlController.php | 2 +- lib/Controller/PageController.php | 4 +- lib/Controller/PodcastController.php | 4 +- .../EpisodeAction/EpisodeActionExtraData.php | 4 +- .../EpisodeAction/EpisodeActionReader.php | 2 +- lib/Service/FyydService.php | 4 +- lib/Service/MultiPodService.php | 2 +- lib/Service/SearchProvider.php | 2 +- lib/Service/UserService.php | 2 +- rector.php | 29 ++++ 14 files changed, 174 insertions(+), 27 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 517c913..31c1f22 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,14 @@ "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", - "psalm": "psalm --threads=1 --no-cache --show-info=true" + "psalm": "psalm --threads=1 --no-cache --show-info=true", + "rector": "rector && composer cs:fix" }, "require-dev": { "nextcloud/ocp": "^30.0.2", - "roave/security-advisories": "dev-latest", "nextcloud/coding-standard": "^1.3.2", + "rector/rector": "^1.2.10", + "roave/security-advisories": "dev-latest", "vimeo/psalm": "^5.26.1" }, "config": { diff --git a/composer.lock b/composer.lock index b6ae45b..e09232a 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": "2bded493404c793fc0cfceedfeccc38c", + "content-hash": "1b3b97dd0074d6decb4ce7f570ef7d4e", "packages": [], "packages-dev": [ { @@ -1049,23 +1049,23 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.9.0", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d" + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/1fb5ba8d045f5dd984ebded5b1cc66f29459422d", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a", + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", - "phpstan/phpdoc-parser": "^1.18" + "phpstan/phpdoc-parser": "^1.18|^2.0" }, "require-dev": { "ext-tokenizer": "*", @@ -1101,9 +1101,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.9.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.10.0" }, - "time": "2024-11-03T20:11:34+00:00" + "time": "2024-11-09T15:12:26+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -1152,6 +1152,64 @@ }, "time": "2024-10-13T11:25:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.12.8", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f6a60a4d66142b8156c9da923f1972657bc4748c", + "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-11-06T19:06:49+00:00" + }, { "name": "psr/clock", "version": "1.0.0", @@ -1353,6 +1411,65 @@ }, "time": "2021-07-14T16:41:46+00:00" }, + { + "name": "rector/rector", + "version": "1.2.10", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "40f9cf38c05296bd32f444121336a521a293fa61" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/40f9cf38c05296bd32f444121336a521a293fa61", + "reference": "40f9cf38c05296bd32f444121336a521a293fa61", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.12.5" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/1.2.10" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2024-11-08T13:59:10+00:00" + }, { "name": "roave/security-advisories", "version": "dev-latest", diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0ca6460..876bc0b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -16,6 +16,7 @@ use OCP\AppFramework\Services\IInitialState; class Application extends App implements IBootstrap { public const APP_ID = 'repod'; + private const GPODDERSYNC_ID = 'gpoddersync'; public function __construct() { @@ -40,7 +41,7 @@ class Application extends App implements IBootstrap if (!$gpoddersync) { try { $appManager->enableApp(self::GPODDERSYNC_ID); - } catch (AppPathNotFoundException $e) { + } catch (AppPathNotFoundException) { } } diff --git a/lib/Controller/EpisodesController.php b/lib/Controller/EpisodesController.php index 58dc462..b656d7d 100644 --- a/lib/Controller/EpisodesController.php +++ b/lib/Controller/EpisodesController.php @@ -37,8 +37,8 @@ class EpisodesController extends Controller $client = $this->clientService->newClient(); $feed = $client->get($url); $episodes = $this->episodeActionReader->parseRssXml((string) $feed->getBody()); - usort($episodes, fn (EpisodeActionExtraData $a, EpisodeActionExtraData $b) => $b->getPubDate() <=> $a->getPubDate()); - $episodes = array_values(array_intersect_key($episodes, array_unique(array_map(fn (EpisodeActionExtraData $episode) => $episode->getGuid(), $episodes)))); + usort($episodes, fn (EpisodeActionExtraData $a, EpisodeActionExtraData $b): int => $b->getPubDate() <=> $a->getPubDate()); + $episodes = array_values(array_intersect_key($episodes, array_unique(array_map(fn (EpisodeActionExtraData $episode): string => $episode->getGuid(), $episodes)))); return new JSONResponse($episodes, $feed->getStatusCode()); } diff --git a/lib/Controller/OpmlController.php b/lib/Controller/OpmlController.php index 4200a82..3dc565e 100644 --- a/lib/Controller/OpmlController.php +++ b/lib/Controller/OpmlController.php @@ -55,7 +55,7 @@ class OpmlController extends Controller foreach ($subscriptions as $subscription) { try { $podcast = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID()); - } catch (\Exception $e) { + } catch (\Exception) { continue; } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index ec114e6..b8e2705 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -11,15 +11,13 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\TemplateResponse; -use OCP\IConfig; use OCP\IRequest; use OCP\Util; class PageController extends Controller { public function __construct( - IRequest $request, - private IConfig $config + IRequest $request ) { parent::__construct(Application::APP_ID, $request); } diff --git a/lib/Controller/PodcastController.php b/lib/Controller/PodcastController.php index 8e2d18f..b54736e 100644 --- a/lib/Controller/PodcastController.php +++ b/lib/Controller/PodcastController.php @@ -36,7 +36,7 @@ class PodcastController extends Controller if ($this->cacheFactory->isLocalCacheAvailable()) { try { $podcast = $this->podcastDataReader->tryGetCachedPodcastData($url); - } catch (\Exception $e) { + } catch (\Exception) { } } @@ -51,7 +51,7 @@ class PodcastController extends Controller if ($this->cacheFactory->isLocalCacheAvailable()) { try { $this->podcastDataReader->trySetCachedPodcastData($url, $podcast); - } catch (\Exception $e) { + } catch (\Exception) { } } diff --git a/lib/Core/EpisodeAction/EpisodeActionExtraData.php b/lib/Core/EpisodeAction/EpisodeActionExtraData.php index ed0bff3..00929ce 100644 --- a/lib/Core/EpisodeAction/EpisodeActionExtraData.php +++ b/lib/Core/EpisodeAction/EpisodeActionExtraData.php @@ -28,7 +28,7 @@ use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction; * action: ?EpisodeActionType * } */ -class EpisodeActionExtraData implements \JsonSerializable +class EpisodeActionExtraData implements \JsonSerializable, \Stringable { public function __construct( private string $title, @@ -120,7 +120,7 @@ class EpisodeActionExtraData implements \JsonSerializable 'size' => $this->size, 'pubDate' => $this->pubDate, 'duration' => $this->duration, - 'action' => $this->action ? $this->action->toArray() : null, + 'action' => $this->action instanceof EpisodeAction ? $this->action->toArray() : null, ]; } diff --git a/lib/Core/EpisodeAction/EpisodeActionReader.php b/lib/Core/EpisodeAction/EpisodeActionReader.php index 0e46159..cc5364d 100644 --- a/lib/Core/EpisodeAction/EpisodeActionReader.php +++ b/lib/Core/EpisodeAction/EpisodeActionReader.php @@ -107,7 +107,7 @@ class EpisodeActionReader extends CoreEpisodeActionReader if (isset($pubDate)) { try { $pubDate = new \DateTime($pubDate); - } catch (\Exception $e) { + } catch (\Exception) { $pubDate = null; } } diff --git a/lib/Service/FyydService.php b/lib/Service/FyydService.php index cc90ae1..5845519 100644 --- a/lib/Service/FyydService.php +++ b/lib/Service/FyydService.php @@ -94,8 +94,8 @@ class FyydService implements IPodProvider if (array_key_exists('data', $langJson) && is_array($langJson['data'])) { $language = in_array($userLang, $langJson['data']) ? $userLang : 'en'; } - } catch (\Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); + } catch (\Exception $exception) { + $this->logger->error($exception->getMessage(), $exception->getTrace()); } $podcastClient = $this->clientService->newClient(); diff --git a/lib/Service/MultiPodService.php b/lib/Service/MultiPodService.php index 5ca82cd..92171b1 100644 --- a/lib/Service/MultiPodService.php +++ b/lib/Service/MultiPodService.php @@ -36,7 +36,7 @@ class MultiPodService implements IPodProvider } } - usort($podcasts, fn (PodcastData $a, PodcastData $b) => $b->getFetchedAtUnix() <=> $a->getFetchedAtUnix()); + usort($podcasts, fn (PodcastData $a, PodcastData $b): int => $b->getFetchedAtUnix() <=> $a->getFetchedAtUnix()); return array_values( array_intersect_key( diff --git a/lib/Service/SearchProvider.php b/lib/Service/SearchProvider.php index 4e201b9..d638fa5 100644 --- a/lib/Service/SearchProvider.php +++ b/lib/Service/SearchProvider.php @@ -30,7 +30,7 @@ class SearchProvider implements IProvider } public function getOrder(string $route, array $routeParameters): int { - if (0 === strpos($route, Application::APP_ID.'.')) { + if (str_starts_with($route, Application::APP_ID.'.')) { // Active app, prefer my results return -1; } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index d4fac42..8cc1bf6 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -27,7 +27,7 @@ class UserService public function getCountryCode(): string { $isoCodes = explode('_', $this->getIsoCode()); - return isset($isoCodes[1]) ? $isoCodes[1] : 'us'; + return $isoCodes[1] ?? 'us'; } public function getLangCode(): string { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..881c2f3 --- /dev/null +++ b/rector.php @@ -0,0 +1,29 @@ +withPaths([ + __DIR__.'/lib', + ]) + ->withPhpSets(php80: true) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + instanceOf: true, + earlyReturn: true, + strictBooleans: true, + rectorPreset: true, + phpunitCodeQuality: true, + doctrineCodeQuality: true, + symfonyCodeQuality: true, + symfonyConfigs: true, + twig: true, + phpunit: true, + ) +;