diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 6a5b3be..88a6c6c 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -63,7 +63,7 @@ jobs: - name: CS run: | cd galette-core/galette/plugins/plugin-paypal - ../../vendor/bin/phpcs -n -p --standard=../../../phpcs-rules.xml lib/ ./*.php + ../../vendor/bin/phpcs lib/ ./*.php - name: Check missing symbols run: | diff --git a/_define.php b/_define.php index 515c80a..e3d96b9 100644 --- a/_define.php +++ b/_define.php @@ -38,7 +38,7 @@ 'Paypal integration', //Short description 'Johan Cwiklinski', //Author '2.0.0', //Version - '1.0.0', //Galette compatible version + '1.1.0', //Galette compatible version 'paypal', //routing name and translation domain '2023-12-07', //Release date [ //Permissions needed diff --git a/lib/GalettePaypal/Controllers/PaypalController.php b/lib/GalettePaypal/Controllers/PaypalController.php index f6167cf..bdd6b50 100644 --- a/lib/GalettePaypal/Controllers/PaypalController.php +++ b/lib/GalettePaypal/Controllers/PaypalController.php @@ -65,10 +65,10 @@ class PaypalController extends AbstractPluginController { /** - * @var array + * @var array */ #[Inject("Plugin Galette Paypal")] - protected $module_info; + protected array $module_info; /** * Main route @@ -129,15 +129,19 @@ public function form(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 mixed $value Option value + * @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 */ - public function logs(Request $request, Response $response, string $option = null, $value = null): Response - { + public function logs( + Request $request, + Response $response, + string $option = null, + string|int $value = null + ): Response { $paypal_history = new PaypalHistory($this->zdb, $this->login, $this->preferences); $filters = $this->session->filter_paypal_history ?? new HistoryList(); diff --git a/lib/GalettePaypal/Paypal.php b/lib/GalettePaypal/Paypal.php index c78d17f..72b1cbf 100644 --- a/lib/GalettePaypal/Paypal.php +++ b/lib/GalettePaypal/Paypal.php @@ -67,14 +67,16 @@ class Paypal public const PAYMENT_PENDING = 'Pending'; public const PAYMENT_COMPLETE = 'Complete'; - private $zdb; + private Db $zdb; - private $prices = array(); - private $id = null; - private $inactives = array(); + /** @var array> */ + private array $prices; + private ?string $id; + /** @var array */ + private array $inactives; - private $loaded = false; - private $amounts_loaded = false; + private bool $loaded; + private bool $amounts_loaded = false; /** * Default constructor @@ -96,7 +98,7 @@ public function __construct(Db $zdb) * * @return void */ - public function load() + public function load(): void { try { $results = $this->zdb->selectAll(PAYPAL_PREFIX . self::PREFS_TABLE); @@ -119,7 +121,7 @@ public function load() } } $this->loaded = true; - return $this->loadAmounts(); + $this->loadAmounts(); } catch (\Exception $e) { Analog::log( '[' . get_class($this) . '] Cannot load paypal preferences |' . @@ -137,7 +139,7 @@ public function load() * * @return void */ - private function loadAmounts() + private function loadAmounts(): void { $ct = new ContributionsTypes($this->zdb); $this->prices = $ct->getCompleteList(); @@ -200,9 +202,9 @@ private function loadAmounts() /** * Store values in the database * - * @return void + * @return bool */ - public function store() + public function store(): bool { try { //store paypal id @@ -257,7 +259,7 @@ public function store() * * @return boolean */ - public function storeAmounts() + public function storeAmounts(): bool { try { $update = $this->zdb->update(PAYPAL_PREFIX . self::TABLE); @@ -296,11 +298,11 @@ public function storeAmounts() /** * Add missing types in paypal table * - * @param Array $queries Array of items to insert + * @param array $queries Array of items to insert * - * @return true on success, false on failure - */ - private function newEntries($queries) + * @return void + */ + private function newEntries(array $queries): void { try { $insert = $this->zdb->insert(PAYPAL_PREFIX . self::TABLE); @@ -320,15 +322,12 @@ private function newEntries($queries) ) ); } - - return true; } catch (\Exception $e) { Analog::log( 'Unable to store missing types in paypal table.' . $stmt->getMessage() . '(' . $stmt->getDebugInfo() . ')', Analog::WARNING ); - return false; } } @@ -337,7 +336,7 @@ private function newEntries($queries) * * @return string */ - public function getId() + public function getId(): string { return $this->id; } @@ -347,9 +346,9 @@ public function getId() * * @param Login $login Login instance * - * @return array + * @return array> */ - public function getAmounts(Login $login) + public function getAmounts(Login $login): array { $prices = array(); foreach ($this->prices as $k => $v) { @@ -365,9 +364,9 @@ public function getAmounts(Login $login) /** * Get loaded amounts * - * @return array + * @return array> */ - public function getAllAmounts() + public function getAllAmounts(): array { return $this->prices; } @@ -377,7 +376,7 @@ public function getAllAmounts() * * @return boolean */ - public function isLoaded() + public function isLoaded(): bool { return $this->loaded; } @@ -387,7 +386,7 @@ public function isLoaded() * * @return boolean */ - public function areAmountsLoaded() + public function areAmountsLoaded(): bool { return $this->amounts_loaded; } @@ -399,7 +398,7 @@ public function areAmountsLoaded() * * @return void */ - public function setId($id) + public function setId(string $id): void { $this->id = $id; } @@ -407,12 +406,12 @@ public function setId($id) /** * Set new prices * - * @param array $ids array of identifier - * @param array $amounts array of amounts + * @param array $ids array of identifier + * @param array $amounts array of amounts * * @return void */ - public function setPrices($ids, $amounts) + public function setPrices(array $ids, array $amounts): void { $this->prices = []; foreach ($ids as $k => $id) { @@ -427,7 +426,7 @@ public function setPrices($ids, $amounts) * * @return boolean */ - public function isInactive($id) + public function isInactive(int $id): bool { return in_array($id, $this->inactives); } @@ -435,11 +434,11 @@ public function isInactive($id) /** * Set inactives types * - * @param array $inactives array of inactives types + * @param array $inactives array of inactives types * * @return void */ - public function setInactives($inactives) + public function setInactives(array $inactives): void { $this->inactives = $inactives; } @@ -449,7 +448,7 @@ public function setInactives($inactives) * * @return void */ - public function unsetInactives() + public function unsetInactives(): void { $this->inactives = array(); } diff --git a/lib/GalettePaypal/PaypalHistory.php b/lib/GalettePaypal/PaypalHistory.php index c0ab6b6..260afd9 100644 --- a/lib/GalettePaypal/PaypalHistory.php +++ b/lib/GalettePaypal/PaypalHistory.php @@ -69,17 +69,17 @@ class PaypalHistory extends History public const STATE_INCOMPLETE = 4; public const STATE_ALREADYDONE = 5; - private $id; + private int $id; /** * Default constructor. * - * @param Db $zdb Database - * @param Login $login Login - * @param Preferences $preferences Preferences - * @param HistoryList $filters Filtering + * @param Db $zdb Database + * @param Login $login Login + * @param Preferences $preferences Preferences + * @param ?HistoryList $filters Filtering */ - public function __construct(Db $zdb, Login $login, Preferences $preferences, $filters = null) + public function __construct(Db $zdb, Login $login, Preferences $preferences, HistoryList $filters = null) { $this->with_lists = false; parent::__construct($zdb, $login, $preferences, $filters); @@ -88,13 +88,13 @@ public function __construct(Db $zdb, Login $login, Preferences $preferences, $fi /** * Add a new entry * - * @param string $action the action to log - * @param string $argument the argument - * @param string $query the query (if relevant) + * @param array|string $action the action to log + * @param string $argument the argument + * @param string $query the query (if relevant) * * @return bool true if entry was successfully added, false otherwise */ - public function add($action, $argument = '', $query = '') + public function add(array|string $action, string $argument = '', string $query = ''): bool { $request = $action; try { @@ -134,7 +134,7 @@ public function add($action, $argument = '', $query = '') * * @return string */ - protected function getTableName($prefixed = false) + protected function getTableName(bool $prefixed = false): string { if ($prefixed === true) { return PREFIX_DB . PAYPAL_PREFIX . self::TABLE; @@ -148,7 +148,7 @@ protected function getTableName($prefixed = false) * * @return string */ - protected function getPk() + protected function getPk(): string { return self::PK; } @@ -156,9 +156,9 @@ protected function getPk() /** * Gets Paypal history * - * @return array + * @return array */ - public function getPaypalHistory() + public function getPaypalHistory(): array { $orig = $this->getHistory(); $new = array(); @@ -210,9 +210,9 @@ function ($match) { /** * Builds the order clause * - * @return string SQL ORDER clause + * @return array SQL ORDER clause */ - protected function buildOrderClause() + protected function buildOrderClause(): array { $order = array(); diff --git a/lib/GalettePaypal/PluginGalettePaypal.php b/lib/GalettePaypal/PluginGalettePaypal.php index 136b5a5..da751e9 100644 --- a/lib/GalettePaypal/PluginGalettePaypal.php +++ b/lib/GalettePaypal/PluginGalettePaypal.php @@ -37,6 +37,7 @@ namespace GalettePaypal; +use Galette\Core\Login; use Galette\Entity\Adherent; use Galette\Core\GalettePlugin; @@ -58,7 +59,7 @@ class PluginGalettePaypal extends GalettePlugin /** * Extra menus entries * - * @return array|array[] + * @return array> */ public static function getMenusContents(): array { @@ -93,7 +94,7 @@ public static function getMenusContents(): array /** * Extra public menus entries * - * @return array|array[] + * @return array> */ public static function getPublicMenusItemsList(): array { @@ -111,7 +112,7 @@ public static function getPublicMenusItemsList(): array /** * Get dashboards contents * - * @return array|array[] + * @return array> */ public static function getDashboardsContents(): array { @@ -123,7 +124,7 @@ public static function getDashboardsContents(): array * * @param Adherent $member Member instance * - * @return array|array[] + * @return array> */ public static function getListActionsContents(Adherent $member): array { @@ -133,9 +134,9 @@ public static function getListActionsContents(Adherent $member): array /** * Get detailed actions contents * - * @param Adherent $member Memebr instance + * @param Adherent $member Member instance * - * @return array|array[] + * @return array> */ public static function getDetailedActionsContents(Adherent $member): array { @@ -145,7 +146,7 @@ public static function getDetailedActionsContents(Adherent $member): array /** * Get batch actions contents * - * @return array|array[] + * @return array> */ public static function getBatchActionsContents(): array {