diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 095c5c1..cec66cd 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -15,9 +15,58 @@ '@PER-CS' => true, '@PHP8x2Migration' => true, 'trailing_comma_in_multiline' => false, - 'cast_spaces' => false, + 'cast_spaces' => ['space' => 'none'], 'single_line_empty_body' => false, - 'no_unused_imports' => true + 'no_unused_imports' => true, + // rules for phpdoc + // Removes @param, @return and @var tags that don't provide any useful information - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:no_superfluous_phpdoc_tags + 'no_superfluous_phpdoc_tags' => [ + 'allow_mixed' => true, + 'remove_inheritdoc' => true, + ], + // require phpdoc for non typed arguments - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_add_missing_param_annotation + 'phpdoc_add_missing_param_annotation' => true, + // no @access - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_no_access + 'phpdoc_no_access' => true, + // no @package - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_no_package + 'phpdoc_no_package' => true, + // order phpdoc tags - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_order + 'phpdoc_order' => ['order' => ['since', 'var', 'see', 'param', 'return', 'throw', 'todo', 'deprecated']], + // phpdoc param in same order as signature - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_param_order + 'phpdoc_param_order' => true, + // align tags - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_align + 'phpdoc_align' => [ + 'align' => 'vertical', + 'tags' => [ + 'param', + 'property', + 'property-read', + 'property-write', + 'phpstan-param', + 'phpstan-property', + 'phpstan-property-read', + 'phpstan-property-write', + 'phpstan-assert', + 'phpstan-assert-if-true', + 'phpstan-assert-if-false', + 'psalm-param', + 'psalm-param-out', + 'psalm-property', + 'psalm-property-read', + 'psalm-property-write', + 'psalm-assert', + 'psalm-assert-if-true', + 'psalm-assert-if-false' + ], + ], + // Check types case - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_types + 'phpdoc_types' => true, + // Use native scalar types - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_scalar + 'phpdoc_scalar' => true, + // remove extra empty lines - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_trim + 'phpdoc_trim' => true, + // remove empty lines inside phpdoc block - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:phpdoc_trim_consecutive_blank_line_separation + 'phpdoc_trim_consecutive_blank_line_separation' => true, ]) ->setFinder($finder) ; diff --git a/.phpcs.xml b/.phpcs.xml index e7cc457..4a33a69 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -16,6 +16,8 @@ + + @@ -23,6 +25,26 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/GaletteHelloasso/Controllers/HelloassoController.php b/lib/GaletteHelloasso/Controllers/HelloassoController.php index c7c717f..f20a88a 100644 --- a/lib/GaletteHelloasso/Controllers/HelloassoController.php +++ b/lib/GaletteHelloasso/Controllers/HelloassoController.php @@ -54,13 +54,8 @@ class HelloassoController extends AbstractPluginController /** * Main form - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ - public function form(Request $request, Response $response): Response + public function form(Response $response): Response { $helloasso = new Helloasso($this->zdb, $this->preferences); @@ -100,20 +95,13 @@ public function form(Request $request, Response $response): Response /** * Checkout form - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ public function formCheckout(Request $request, Response $response): Response { $helloasso_request = $request->getParsedBody(); $helloasso = new Helloasso($this->zdb, $this->preferences); $adherent = new Adherent($this->zdb); - $contribution_type = new ContributionsTypes($this->zdb, (int) $helloasso_request['item_id']); - - $current_url = $this->preferences->getURL(); + $contribution_type = new ContributionsTypes($this->zdb, (int)$helloasso_request['item_id']); // Check the amount $item_id = $helloasso_request['item_id']; @@ -165,15 +153,10 @@ public function formCheckout(Request $request, Response $response): Response /** * Logs page * - * @param Request $request PSR Request - * @param Response $response PSR Response - * @param string|null $option Either order, reset or page - * @param string|int|null $value Option value - * - * @return Response + * @param string|null $option Either order, reset or page + * @param string|int|null $value Option value */ public function logs( - Request $request, Response $response, ?string $option = null, string|int|null $value = null @@ -190,7 +173,7 @@ public function logs( if ($option !== null) { switch ($option) { case 'page': - $filters->current_page = (int) $value; + $filters->current_page = (int)$value; break; case 'order': $filters->orderby = $value; @@ -229,11 +212,6 @@ public function logs( /** * Filter - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ public function filter(Request $request, Response $response): Response { @@ -256,11 +234,6 @@ public function filter(Request $request, Response $response): Response /** * Preferences - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ public function preferences(Request $request, Response $response): Response { @@ -294,11 +267,6 @@ public function preferences(Request $request, Response $response): Response /** * Store Preferences - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ public function storePreferences(Request $request, Response $response): Response { @@ -354,11 +322,6 @@ public function storePreferences(Request $request, Response $response): Response /** * Webhook - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ public function webhook(Request $request, Response $response): Response { @@ -487,13 +450,8 @@ public function webhook(Request $request, Response $response): Response /** * Return URL - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ - public function returnUrl(Request $request, Response $response): Response + public function returnUrl(Response $response): Response { $params = [ 'page_title' => _T('Helloasso payment success', 'helloasso') @@ -510,13 +468,8 @@ public function returnUrl(Request $request, Response $response): Response /** * Cancel URL - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ - public function cancelUrl(Request $request, Response $response): Response + public function cancelUrl(Response $response): Response { $this->flash->addMessage( 'warning_detected', @@ -529,11 +482,6 @@ public function cancelUrl(Request $request, Response $response): Response /** * Error URL - * - * @param Request $request PSR Request - * @param Response $response PSR Response - * - * @return Response */ public function errorUrl(Request $request, Response $response): Response { diff --git a/lib/GaletteHelloasso/Helloasso.php b/lib/GaletteHelloasso/Helloasso.php index 4fde64c..bb3ba9d 100644 --- a/lib/GaletteHelloasso/Helloasso.php +++ b/lib/GaletteHelloasso/Helloasso.php @@ -99,8 +99,6 @@ public function __construct(Db $zdb, Preferences $preferences) /** * Load preferences form the database and amounts from core contributions types - * - * @return void */ public function load(): void { @@ -157,8 +155,6 @@ public function load(): void /** * Load amounts from core contributions types - * - * @return void */ private function loadContributionsTypes(): void { @@ -180,8 +176,6 @@ private function loadContributionsTypes(): void /** * Store values in the database - * - * @return bool */ public function store(): bool { @@ -199,7 +193,7 @@ public function store(): bool ] ); - $edit = $this->zdb->execute($update); + $this->zdb->execute($update); //store Helloasso organization slug $values = [ @@ -214,7 +208,7 @@ public function store(): bool ] ); - $edit = $this->zdb->execute($update); + $this->zdb->execute($update); //store Helloasso clientId $values = [ @@ -229,7 +223,7 @@ public function store(): bool ] ); - $edit = $this->zdb->execute($update); + $this->zdb->execute($update); //store Helloasso clientSecret $values = [ @@ -244,7 +238,7 @@ public function store(): bool ] ); - $edit = $this->zdb->execute($update); + $this->zdb->execute($update); //store inactives $values = [ @@ -259,7 +253,7 @@ public function store(): bool ] ); - $edit = $this->zdb->execute($update); + $this->zdb->execute($update); Analog::log( '[' . get_class($this) @@ -280,8 +274,6 @@ public function store(): bool /** * Store tokens - * - * @return bool */ private function storeTokens(): bool { @@ -337,8 +329,6 @@ private function storeTokens(): bool * @param array $metadata Array of metadata to transmit with payment * @param float $amount Amount of payment * @param ?bool $contains_donation Does the checkout contain a donation? - * - * @return array|bool */ public function checkout(array $metadata, float $amount, ?bool $contains_donation = false): array|bool { @@ -391,8 +381,6 @@ public function checkout(array $metadata, float $amount, ?bool $contains_donatio /** * Setup Guzzle client - * - * @return Client */ public function setupClient(): Client { @@ -430,8 +418,6 @@ public function getTokens(): ?array /** * Is access token expired ? - * - * @return bool */ public function isAccessTokenExpired(): bool { @@ -443,8 +429,6 @@ public function isAccessTokenExpired(): bool /** * Is refresh token expired ? - * - * @return bool */ public function isRefreshTokenExpired(): bool { @@ -456,8 +440,6 @@ public function isRefreshTokenExpired(): bool /** * Get credentials - * - * @return bool */ private function getCredentials(): bool { @@ -470,8 +452,6 @@ private function getCredentials(): bool /** * Refresh credentials - * - * @return bool */ private function refreshCredentials(): bool { @@ -486,8 +466,6 @@ private function refreshCredentials(): bool * Get client credentials * * @param array $parameters Parameters required by API - * - * @return bool */ private function getClientCredentials(array $parameters): bool { @@ -523,8 +501,6 @@ private function getClientCredentials(array $parameters): bool * Get API route * * @param ?bool $auth Get authentification route if true - * - * @return string */ public function getApiRoute(?bool $auth = null): string { @@ -568,8 +544,6 @@ public function getOrganization(): array /** * Get test mode - * - * @return bool */ public function getTestMode(): bool { @@ -578,8 +552,6 @@ public function getTestMode(): bool /** * Get Helloasso organization slug - * - * @return string */ public function getOrganizationSlug(): ?string { @@ -588,8 +560,6 @@ public function getOrganizationSlug(): ?string /** * Get Helloasso clientId - * - * @return string */ public function getClientId(): ?string { @@ -598,8 +568,6 @@ public function getClientId(): ?string /** * Get Helloasso clientSecret - * - * @return string */ public function getClientSecret(): ?string { @@ -639,8 +607,6 @@ public function getAllAmounts(): array /** * Is the plugin loaded? - * - * @return boolean */ public function isLoaded(): bool { @@ -649,8 +615,6 @@ public function isLoaded(): bool /** * Are amounts loaded? - * - * @return boolean */ public function areAmountsLoaded(): bool { @@ -661,8 +625,6 @@ public function areAmountsLoaded(): bool * Set Test mode * * @param bool $enabled True to enable test mode - * - * @return void */ public function setTestMode(bool $enabled): void { @@ -673,8 +635,6 @@ public function setTestMode(bool $enabled): void * Set Helloasso organization slug * * @param string $organization_slug organization slug - * - * @return void */ public function setOrganizationSlug(string $organization_slug): void { @@ -685,8 +645,6 @@ public function setOrganizationSlug(string $organization_slug): void * Set Helloasso clientId * * @param string $client_id clientId - * - * @return void */ public function setClientId(string $client_id): void { @@ -697,8 +655,6 @@ public function setClientId(string $client_id): void * Set Helloasso clientSecret * * @param string $client_secret clientSecret - * - * @return void */ public function setClientSecret(string $client_secret): void { @@ -710,8 +666,6 @@ public function setClientSecret(string $client_secret): void * * @param array $ids array of identifier * @param array $amounts array of amounts - * - * @return void */ public function setPrices(array $ids, array $amounts): void { @@ -725,8 +679,6 @@ public function setPrices(array $ids, array $amounts): void * Check if the specified contribution is active * * @param int $id type identifier - * - * @return boolean */ public function isInactive(int $id): bool { @@ -737,8 +689,6 @@ public function isInactive(int $id): bool * Set inactives types * * @param array $inactives array of inactives types - * - * @return void */ public function setInactives(array $inactives): void { @@ -747,8 +697,6 @@ public function setInactives(array $inactives): void /** * Unset inactives types - * - * @return void */ public function unsetInactives(): void { diff --git a/lib/GaletteHelloasso/HelloassoHistory.php b/lib/GaletteHelloasso/HelloassoHistory.php index 388c6a1..aaf94ab 100644 --- a/lib/GaletteHelloasso/HelloassoHistory.php +++ b/lib/GaletteHelloasso/HelloassoHistory.php @@ -89,7 +89,7 @@ public function add(array|string $action, string $argument = '', string $query = $insert = $this->zdb->insert($this->getTableName()); $insert->values($values); $this->zdb->execute($insert); - $this->id = (int) $this->zdb->driver->getLastGeneratedValue(); + $this->id = (int)$this->zdb->driver->getLastGeneratedValue(); Analog::log( 'An entry has been added in helloasso history', @@ -109,9 +109,7 @@ public function add(array|string $action, string $argument = '', string $query = /** * Get table's name * - * @param boolean $prefixed Whether table name should be prefixed - * - * @return string + * @param bool $prefixed Whether table name should be prefixed */ protected function getTableName(bool $prefixed = false): string { @@ -124,8 +122,6 @@ protected function getTableName(bool $prefixed = false): string /** * Get table's PK - * - * @return string */ protected function getPk(): string { @@ -134,8 +130,6 @@ protected function getPk(): string /** * Gets Helloasso history - * - * @return array */ public function getHelloassoHistory(): array { @@ -192,8 +186,6 @@ protected function buildOrderClause(): array * Is payment already processed? * * @param array $request Verify sign helloasso parameter - * - * @return boolean */ public function isProcessed(array $request): bool { @@ -212,9 +204,7 @@ public function isProcessed(array $request): bool /** * Set payment state * - * @param integer $state State, one of self::STATE_ constants - * - * @return boolean + * @param int $state State, one of self::STATE_ constants */ public function setState(int $state): bool { diff --git a/tests/GaletteHelloasso/tests/units/Helloasso.php b/tests/GaletteHelloasso/tests/units/Helloasso.php index 9d9d3ed..35803a8 100644 --- a/tests/GaletteHelloasso/tests/units/Helloasso.php +++ b/tests/GaletteHelloasso/tests/units/Helloasso.php @@ -35,8 +35,6 @@ class Helloasso extends GaletteTestCase /** * Cleanup after each test method - * - * @return void */ public function tearDown(): void { @@ -47,8 +45,6 @@ public function tearDown(): void /** * Test empty - * - * @return void */ public function testEmpty(): void {