From bf0663e20ecccc72db9f978609b2841197e56d57 Mon Sep 17 00:00:00 2001 From: Davide Porrovecchio Date: Tue, 24 Oct 2023 15:50:36 +0200 Subject: [PATCH] Fix code style and rules --- .php-cs-fixer.dist.php | 3 +- app/Contracts/AnalyticsService.php | 2 +- app/Extensions/AppUserProvider.php | 6 +- app/Http/Controllers/AnalyticsController.php | 2 +- .../AnalyticsServiceController.php | 2 +- app/Notifications/UserEmailNotification.php | 2 +- .../UserPublicAdministrationChangedEmail.php | 2 +- app/Services/MatomoService.php | 2 +- app/Services/SingleDigitalGatewayService.php | 2 +- .../Feature/ArchiveWebsiteJsonRoutesTest.php | 108 +++++++++--------- tests/SqliteForeignKeyHotfix.php | 2 +- 11 files changed, 67 insertions(+), 66 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 45e152db2..b266556fb 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -26,7 +26,8 @@ 'phpdoc_align' => ['align' => 'left'], 'phpdoc_no_empty_return' => false, 'phpdoc_order' => true, - 'global_namespace_import' => ['import_classes' => true] + 'global_namespace_import' => ['import_classes' => true], + 'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true] ]; $finder = Finder::create() diff --git a/app/Contracts/AnalyticsService.php b/app/Contracts/AnalyticsService.php index 0b9cbcca2..f87bdbf9d 100644 --- a/app/Contracts/AnalyticsService.php +++ b/app/Contracts/AnalyticsService.php @@ -173,7 +173,7 @@ public function getUsersLogin(): array; * * @return RedirectResponse the Analytics service dashboard */ - public function loginAndRedirectUser(string $userLogin, string $hashedPassword, string $idSite = null): RedirectResponse; + public function loginAndRedirectUser(string $userLogin, string $hashedPassword, ?string $idSite = null): RedirectResponse; /** * Set permissions for a specified user and specified websites diff --git a/app/Extensions/AppUserProvider.php b/app/Extensions/AppUserProvider.php index d49ac6c77..4dcde5807 100644 --- a/app/Extensions/AppUserProvider.php +++ b/app/Extensions/AppUserProvider.php @@ -25,9 +25,9 @@ class AppUserProvider extends EloquentUserProvider */ public function retrieveByCredentials(array $credentials): ?Authenticatable { - if (empty($credentials) || - (1 === count($credentials) && - array_key_exists('password', $credentials))) { + if (empty($credentials) + || (1 === count($credentials) + && array_key_exists('password', $credentials))) { return null; } // First we will add each credential element to the query as a where clause. diff --git a/app/Http/Controllers/AnalyticsController.php b/app/Http/Controllers/AnalyticsController.php index 5c7bc50a2..5995cca16 100644 --- a/app/Http/Controllers/AnalyticsController.php +++ b/app/Http/Controllers/AnalyticsController.php @@ -20,7 +20,7 @@ class AnalyticsController extends Controller * * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse */ - public function index(Request $request, PublicAdministration $publicAdministration = null) + public function index(Request $request, ?PublicAdministration $publicAdministration = null) { $user = $request->user(); diff --git a/app/Http/Controllers/AnalyticsServiceController.php b/app/Http/Controllers/AnalyticsServiceController.php index 225113025..031e2d460 100644 --- a/app/Http/Controllers/AnalyticsServiceController.php +++ b/app/Http/Controllers/AnalyticsServiceController.php @@ -16,7 +16,7 @@ class AnalyticsServiceController extends Controller * * @return RedirectResponse the server redirect response */ - public function login(string $websiteAnalyticsId = null): RedirectResponse + public function login(?string $websiteAnalyticsId = null): RedirectResponse { $user = auth()->user(); if (!$user->hasAnalyticsServiceAccount()) { diff --git a/app/Notifications/UserEmailNotification.php b/app/Notifications/UserEmailNotification.php index 6f91b3473..8bdab8bef 100644 --- a/app/Notifications/UserEmailNotification.php +++ b/app/Notifications/UserEmailNotification.php @@ -34,7 +34,7 @@ abstract class UserEmailNotification extends EmailNotification * @param PublicAdministration $publicAdministration the public administration * @param string $recipientEmail the email address to use for thins notification */ - public function __construct(PublicAdministration $publicAdministration = null, string $recipientEmail = null) + public function __construct(?PublicAdministration $publicAdministration = null, ?string $recipientEmail = null) { $this->publicAdministration = $publicAdministration; $this->recipientEmail = $recipientEmail; diff --git a/app/Notifications/UserPublicAdministrationChangedEmail.php b/app/Notifications/UserPublicAdministrationChangedEmail.php index 911fb89b6..61baaca78 100644 --- a/app/Notifications/UserPublicAdministrationChangedEmail.php +++ b/app/Notifications/UserPublicAdministrationChangedEmail.php @@ -25,7 +25,7 @@ class UserPublicAdministrationChangedEmail extends UserEmailNotification * @param string $recipientEmail the email address to use for thins notification * @param string $updatedEmail the updated email address */ - public function __construct(PublicAdministration $publicAdministration = null, string $recipientEmail = null, string $updatedEmail) + public function __construct(?PublicAdministration $publicAdministration = null, ?string $recipientEmail = null, string $updatedEmail) { parent::__construct($publicAdministration, $recipientEmail); $this->updatedEmail = $updatedEmail; diff --git a/app/Services/MatomoService.php b/app/Services/MatomoService.php index d728b328d..921ba04b3 100644 --- a/app/Services/MatomoService.php +++ b/app/Services/MatomoService.php @@ -396,7 +396,7 @@ public function getUsersLogin(): array * * @return RedirectResponse the Analytics service dashboard */ - public function loginAndRedirectUser(string $userLogin, string $hashedPassword, string $idSite = null): RedirectResponse + public function loginAndRedirectUser(string $userLogin, string $hashedPassword, ?string $idSite = null): RedirectResponse { return redirect($this->servicePublicUrl . '/index.php?module=Login&action=logme&login=' . $userLogin . '&password=' . $hashedPassword . '&idSite=' . $idSite); } diff --git a/app/Services/SingleDigitalGatewayService.php b/app/Services/SingleDigitalGatewayService.php index 70cf8dd06..6c288ffb5 100644 --- a/app/Services/SingleDigitalGatewayService.php +++ b/app/Services/SingleDigitalGatewayService.php @@ -142,7 +142,7 @@ public function validatePayload($dataset): void * * @throws SDGServiceException */ - protected function apiCall(string $path, string $method = 'GET', array $params = [], array $body = null) + protected function apiCall(string $path, string $method = 'GET', array $params = [], ?array $body = null) { $apiLogger = Log::channel('sdg_api'); $stack = HandlerStack::create(); diff --git a/tests/Feature/ArchiveWebsiteJsonRoutesTest.php b/tests/Feature/ArchiveWebsiteJsonRoutesTest.php index d98baf6ea..ca7274443 100644 --- a/tests/Feature/ArchiveWebsiteJsonRoutesTest.php +++ b/tests/Feature/ArchiveWebsiteJsonRoutesTest.php @@ -203,33 +203,33 @@ public function testArchiveWebsiteFailedWrongStatusRoute(): void Event::assertNotDispatched(WebsiteUnarchived::class); } -// to be uncommented after the resolution of https://github.com/matomo-org/matomo/issues/8697 -// /** -// * Test website archive failed due to error in Analytics Service call. -// */ -// public function testArchiveWebsiteFailedRoute(): void -// { -// $website = factory(Website::class)->create([ -// 'public_administration_id' => $this->publicAdministration->id, -// 'type' => WebsiteType::INFORMATIONAL, -// 'status' => WebsiteStatus::ACTIVE, -// ]); -// -// $response = $this->actingAs($this->user) -// ->withSession([ -// 'spid_sessionId' => 'fake-session-index', -// 'tenant_id' => $this->publicAdministration->id, -// ]) -// ->json('patch', route('websites.archive', ['website' => $website->slug])); -// -// $response->assertJson([ -// 'result' => 'error', -// 'message' => 'Bad Request', -// ]); -// -// Event::assertNotDispatched(WebsiteArchived::class); -// Event::assertNotDispatched(WebsiteUnarchived::class); -// } + // to be uncommented after the resolution of https://github.com/matomo-org/matomo/issues/8697 + // /** + // * Test website archive failed due to error in Analytics Service call. + // */ + // public function testArchiveWebsiteFailedRoute(): void + // { + // $website = factory(Website::class)->create([ + // 'public_administration_id' => $this->publicAdministration->id, + // 'type' => WebsiteType::INFORMATIONAL, + // 'status' => WebsiteStatus::ACTIVE, + // ]); + // + // $response = $this->actingAs($this->user) + // ->withSession([ + // 'spid_sessionId' => 'fake-session-index', + // 'tenant_id' => $this->publicAdministration->id, + // ]) + // ->json('patch', route('websites.archive', ['website' => $website->slug])); + // + // $response->assertJson([ + // 'result' => 'error', + // 'message' => 'Bad Request', + // ]); + // + // Event::assertNotDispatched(WebsiteArchived::class); + // Event::assertNotDispatched(WebsiteUnarchived::class); + // } /** * Test website re-enable status not modified response. @@ -336,31 +336,31 @@ public function testUnarchiveWebsiteFailedWrongStatusRoute(): void Event::assertNotDispatched(WebsiteUnarchived::class); } -// to be uncommented after the resolution of https://github.com/matomo-org/matomo/issues/8697 -// /** -// * Test website archive failed due to error in Analytics Service call. -// */ -// public function testUnarchiveWebsiteFailedRoute(): void -// { -// $website = factory(Website::class)->create([ -// 'public_administration_id' => $this->publicAdministration->id, -// 'status' => WebsiteStatus::ARCHIVED, -// 'type' => WebsiteType::INFORMATIONAL, -// ]); -// -// $response = $this->actingAs($this->user) -// ->withSession([ -// 'spid_sessionId' => 'fake-session-index', -// 'tenant_id' => $this->publicAdministration->id, -// ]) -// ->json('patch', route('websites.unarchive', ['website' => $website->slug])); -// -// $response->assertJson([ -// 'result' => 'error', -// 'message' => 'Bad Request', -// ]); -// -// Event::assertNotDispatched(WebsiteArchived::class); -// Event::assertNotDispatched(WebsiteUnarchived::class); -// } + // to be uncommented after the resolution of https://github.com/matomo-org/matomo/issues/8697 + // /** + // * Test website archive failed due to error in Analytics Service call. + // */ + // public function testUnarchiveWebsiteFailedRoute(): void + // { + // $website = factory(Website::class)->create([ + // 'public_administration_id' => $this->publicAdministration->id, + // 'status' => WebsiteStatus::ARCHIVED, + // 'type' => WebsiteType::INFORMATIONAL, + // ]); + // + // $response = $this->actingAs($this->user) + // ->withSession([ + // 'spid_sessionId' => 'fake-session-index', + // 'tenant_id' => $this->publicAdministration->id, + // ]) + // ->json('patch', route('websites.unarchive', ['website' => $website->slug])); + // + // $response->assertJson([ + // 'result' => 'error', + // 'message' => 'Bad Request', + // ]); + // + // Event::assertNotDispatched(WebsiteArchived::class); + // Event::assertNotDispatched(WebsiteUnarchived::class); + // } } diff --git a/tests/SqliteForeignKeyHotfix.php b/tests/SqliteForeignKeyHotfix.php index 51c801367..a33ef6311 100644 --- a/tests/SqliteForeignKeyHotfix.php +++ b/tests/SqliteForeignKeyHotfix.php @@ -22,7 +22,7 @@ public function getSchemaBuilder() } return new class($this) extends SQLiteBuilder { - protected function createBlueprint($table, Closure $callback = null) + protected function createBlueprint($table, ?Closure $callback = null) { return new class($table, $callback) extends Blueprint { public function dropForeign($index)