From 1a024bdec74756dd33e838e2b3ff9af1f01a1f74 Mon Sep 17 00:00:00 2001 From: Yassine Doghri <yassine@doghri.fr> Date: Thu, 20 May 2021 17:13:13 +0000 Subject: [PATCH] ci: fix rector issues for code-review job to pass --- .gitlab-ci.yml | 2 +- app/Config/Pager.php | 4 +++- app/Config/Services.php | 4 ++++ app/Controllers/Admin/ContributorController.php | 2 +- app/Controllers/InstallController.php | 6 +++--- app/Entities/Category.php | 3 +++ app/Helpers/components_helper.php | 5 ++--- .../ActivityPub/Helpers/activitypub_helper.php | 6 +++--- app/Models/PersonModel.php | 13 +++++-------- composer.json | 2 +- composer.lock | 15 +++++++-------- public/index.php | 6 +++--- tests/_support/DatabaseTestCase.php | 3 ++- 13 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b91929807d..bdecaedb44 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,7 +54,7 @@ static-analysis: code-review: stage: quality script: - - vendor/bin/rector process --dry-run --ansi --verbose + - vendor/bin/rector process --dry-run --ansi bundle_app: stage: bundle diff --git a/app/Config/Pager.php b/app/Config/Pager.php index 942f2923fa..eb14d9a578 100644 --- a/app/Config/Pager.php +++ b/app/Config/Pager.php @@ -19,8 +19,10 @@ class Pager extends BaseConfig * and the desired group as $pagerGroup; * * @var array<string, string> + * + * @noRector Rector\Php55\Rector\String_\StringClassNameToClassConstantRector */ - public array $templates = [ + public $templates = [ 'default_full' => 'App\Views\pager\default_full', 'default_simple' => 'CodeIgniter\Pager\Views\default_simple', 'default_head' => 'CodeIgniter\Pager\Views\default_head', diff --git a/app/Config/Services.php b/app/Config/Services.php index 97510ec8be..517459be1c 100644 --- a/app/Config/Services.php +++ b/app/Config/Services.php @@ -31,6 +31,8 @@ class Services extends BaseService /** * The Router class uses a RouteCollection's array of routes, and determines the correct Controller and Method to * execute. + * + * @noRector PHPStan\Reflection\MissingMethodFromReflectionException */ public static function router( ?RouteCollectionInterface $routes = null, @@ -50,6 +52,8 @@ class Services extends BaseService /** * The Negotiate class provides the content negotiation features for working the request to determine correct * language, encoding, charset, and more. + * + * @noRector PHPStan\Reflection\MissingMethodFromReflectionException */ public static function negotiator(?RequestInterface $request = null, bool $getShared = true): Negotiate { diff --git a/app/Controllers/Admin/ContributorController.php b/app/Controllers/Admin/ContributorController.php index 451ad14f09..54abfd3ad7 100644 --- a/app/Controllers/Admin/ContributorController.php +++ b/app/Controllers/Admin/ContributorController.php @@ -32,7 +32,7 @@ class ContributorController extends BaseController } if ( - $this->user = (new UserModel())->getPodcastContributor((int) $params[1], (int) $params[0],) + ($this->user = (new UserModel())->getPodcastContributor((int) $params[1], (int) $params[0],)) !== null ) { return $this->{$method}(); } diff --git a/app/Controllers/InstallController.php b/app/Controllers/InstallController.php index 8effca3050..9b6f92082c 100644 --- a/app/Controllers/InstallController.php +++ b/app/Controllers/InstallController.php @@ -68,7 +68,7 @@ class InstallController extends Controller if (is_really_writable(ROOTPATH . '.env')) { try { $dotenv->required(['app.baseURL', 'app.adminGateway', 'app.authGateway']); - } catch (ValidationException $e) { + } catch (ValidationException) { // form to input instance configuration return $this->instanceConfig(); } @@ -81,7 +81,7 @@ class InstallController extends Controller 'database.default.password', 'database.default.DBPrefix', ]); - } catch (ValidationException $validationException) { + } catch (ValidationException) { return $this->databaseConfig(); } @@ -343,7 +343,7 @@ class InstallController extends Controller $keyVal = $key . '="' . $value . '"' . PHP_EOL; $envData = array_map( function ($line) use ($key, $keyVal, &$replaced) { - if (str_starts_with($line, (string) $key)) { + if (str_starts_with($line, $key)) { $replaced = true; return $keyVal; } diff --git a/app/Entities/Category.php b/app/Entities/Category.php index e56415e2df..e3d9ceaddc 100644 --- a/app/Entities/Category.php +++ b/app/Entities/Category.php @@ -34,6 +34,9 @@ class Category extends Entity 'google_category' => 'string', ]; + /** + * @noRector ReturnTypeDeclarationRector + */ public function getParent(): ?self { if ($this->parent_id === null) { diff --git a/app/Helpers/components_helper.php b/app/Helpers/components_helper.php index ef161d204b..5a869b2f28 100644 --- a/app/Helpers/components_helper.php +++ b/app/Helpers/components_helper.php @@ -426,6 +426,7 @@ if (! function_exists('person_list')) { $person->full_name . '</strong>' . implode( + '', array_map(function ($role) { return '<br />' . lang( @@ -443,9 +444,7 @@ if (! function_exists('person_list')) { ); } - $personList .= '</div>'; - - return $personList; + return $personList . '</div>'; } } diff --git a/app/Libraries/ActivityPub/Helpers/activitypub_helper.php b/app/Libraries/ActivityPub/Helpers/activitypub_helper.php index 65f05ef500..c56f444e4c 100644 --- a/app/Libraries/ActivityPub/Helpers/activitypub_helper.php +++ b/app/Libraries/ActivityPub/Helpers/activitypub_helper.php @@ -40,7 +40,7 @@ if (! function_exists('split_handle')) { * * @return array<string, string>|false */ - function split_handle(string $handle) + function split_handle(string $handle): array | false { if ( ! preg_match('~^@?(?P<username>[\w\.\-]+)@(?P<domain>[\w\.\-]+)(?P<port>:[\d]+)?$~', $handle, $matches,) @@ -106,9 +106,9 @@ if (! function_exists('send_activity_to_followers')) { $acceptRequest = new ActivityRequest($follower->inbox_url, $activityPayload,); $acceptRequest->sign($actor->public_key_id, $actor->private_key,); $acceptRequest->post(); - } catch (Exception $e) { + } catch (Exception $exception) { // log error - log_message('critical', $e); + log_message('critical', $exception); } } } diff --git a/app/Models/PersonModel.php b/app/Models/PersonModel.php index ba8ea2c52d..74f5598dd2 100644 --- a/app/Models/PersonModel.php +++ b/app/Models/PersonModel.php @@ -11,6 +11,7 @@ namespace App\Models; use App\Entities\Image; use App\Entities\Person; use CodeIgniter\Database\BaseResult; +use CodeIgniter\Database\Query; use CodeIgniter\Model; class PersonModel extends Model @@ -171,7 +172,6 @@ class PersonModel extends Model ->getLocale(); $cacheName = "taxonomy_options_{$locale}"; - /** @var array<string, array> */ $personsTaxonomy = lang('PersonsTaxonomy.persons'); if (! ($options = cache($cacheName))) { @@ -254,7 +254,7 @@ class PersonModel extends Model int $personId, string $groupSlug, string $roleSlug - ): int | bool { + ): bool | Query { return $this->db->table('episodes_persons') ->insert([ 'podcast_id' => $podcastId, @@ -270,7 +270,7 @@ class PersonModel extends Model int $personId, string $groupSlug, string $roleSlug - ): int | bool { + ): bool | Query { return $this->db->table('podcasts_persons') ->insert([ 'podcast_id' => $podcastId, @@ -329,7 +329,7 @@ class PersonModel extends Model * * @return BaseResult|bool Number of rows inserted or FALSE on failure */ - public function removePersonFromPodcast(int $podcastId, int $personId): BaseResult | bool + public function removePersonFromPodcast(int $podcastId, int $personId): bool | string { return $this->db->table('podcasts_persons') ->delete([ @@ -384,10 +384,7 @@ class PersonModel extends Model return 0; } - /** - * @return BaseResult|bool - */ - public function removePersonFromEpisode(int $podcastId, int $episodeId, int $personId): BaseResult | bool + public function removePersonFromEpisode(int $podcastId, int $episodeId, int $personId): bool | string { return $this->db->table('episodes_persons') ->delete([ diff --git a/composer.json b/composer.json index 6dc728e9c7..316ee12d14 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require-dev": { "mikey179/vfsstream": "^v1.6.8", "phpunit/phpunit": "^9.5.4", - "rector/rector": "^0.10.22", + "rector/rector": "^0.11.5", "captainhook/captainhook": "^5.10.0", "captainhook/plugin-composer": "^5.2", "phpstan/phpstan": "^0.12.85", diff --git a/composer.lock b/composer.lock index 7eaa854ef1..3cb9e81e83 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": "906f0d5a3cf8e20fa22205278198f8f3", + "content-hash": "f66c02dfe61b7fe87d93f4db5a1f9c26", "packages": [ { "name": "brick/math", @@ -3730,16 +3730,16 @@ }, { "name": "rector/rector", - "version": "dev-main", + "version": "0.11.5", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "feba977d4e85ffc9269b84f8fcaa37b7aecc3e05" + "reference": "270eaef34d0f34b49ad0fc3e44cff377b9aa04ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/feba977d4e85ffc9269b84f8fcaa37b7aecc3e05", - "reference": "feba977d4e85ffc9269b84f8fcaa37b7aecc3e05", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/270eaef34d0f34b49ad0fc3e44cff377b9aa04ce", + "reference": "270eaef34d0f34b49ad0fc3e44cff377b9aa04ce", "shasum": "" }, "require": { @@ -3757,7 +3757,6 @@ "rector/rector-prefixed": "*", "rector/rector-symfony": "*" }, - "default-branch": true, "bin": [ "bin/rector" ], @@ -3779,7 +3778,7 @@ "description": "Prefixed and PHP 7.1 downgraded version of rector/rector", "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/main" + "source": "https://github.com/rectorphp/rector/tree/0.11.5" }, "funding": [ { @@ -3787,7 +3786,7 @@ "type": "github" } ], - "time": "2021-05-19T14:34:37+00:00" + "time": "2021-05-18T13:45:09+00:00" }, { "name": "rector/rector-phpstan-rules", diff --git a/public/index.php b/public/index.php index a0451b7dfd..3ae1e59b74 100644 --- a/public/index.php +++ b/public/index.php @@ -3,10 +3,10 @@ use Config\Paths; // Valid PHP Version? -$minPHPVersion = '8.0'; -if (version_compare(PHP_VERSION, $minPHPVersion, '<')) { +$minPHPVersionId = 80000; // 8.0 +if ($minPHPVersionId > PHP_VERSION_ID) { die( - "Your PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: " . + 'Your PHP version must be 8.0 or higher to run Castopod Host. Current version: ' . PHP_VERSION ); } diff --git a/tests/_support/DatabaseTestCase.php b/tests/_support/DatabaseTestCase.php index fdab9b9813..ad81dd3441 100644 --- a/tests/_support/DatabaseTestCase.php +++ b/tests/_support/DatabaseTestCase.php @@ -4,6 +4,7 @@ namespace Tests\Support; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; +use Tests\Support\Database\Seeds\ExampleSeeder; /** * @phpstan-ignore-next-line @@ -24,7 +25,7 @@ class DatabaseTestCase extends CIUnitTestCase * * @var string|string[] */ - protected $seed = 'Tests\Support\Database\Seeds\ExampleSeeder'; + protected $seed = ExampleSeeder::class; /** * The path to the seeds directory. Allows overriding the default application directories. -- GitLab