Skip to content

Commit

Permalink
Galette 1.1.0 compat, typehint
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Jan 24, 2024
1 parent a43542e commit 6e1db6b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion _define.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions lib/GalettePaypal/Controllers/PaypalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
class PaypalController extends AbstractPluginController
{
/**
* @var array
* @var array<string, mixed>
*/
#[Inject("Plugin Galette Paypal")]
protected $module_info;
protected array $module_info;

/**
* Main route
Expand Down Expand Up @@ -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();
Expand Down
67 changes: 33 additions & 34 deletions lib/GalettePaypal/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, array<string,mixed>> */
private array $prices;
private ?string $id;
/** @var array<int, string> */
private array $inactives;

private $loaded = false;
private $amounts_loaded = false;
private bool $loaded;
private bool $amounts_loaded = false;

/**
* Default constructor
Expand All @@ -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);
Expand All @@ -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 |' .
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -296,11 +298,11 @@ public function storeAmounts()
/**
* Add missing types in paypal table
*
* @param Array $queries Array of items to insert
* @param array<string, string> $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);
Expand All @@ -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;
}
}

Expand All @@ -337,7 +336,7 @@ private function newEntries($queries)
*
* @return string
*/
public function getId()
public function getId(): string
{
return $this->id;
}
Expand All @@ -347,9 +346,9 @@ public function getId()
*
* @param Login $login Login instance
*
* @return array
* @return array<int, array<string,mixed>>
*/
public function getAmounts(Login $login)
public function getAmounts(Login $login): array
{
$prices = array();
foreach ($this->prices as $k => $v) {
Expand All @@ -365,9 +364,9 @@ public function getAmounts(Login $login)
/**
* Get loaded amounts
*
* @return array
* @return array<int, array<string,mixed>>
*/
public function getAllAmounts()
public function getAllAmounts(): array
{
return $this->prices;
}
Expand All @@ -377,7 +376,7 @@ public function getAllAmounts()
*
* @return boolean
*/
public function isLoaded()
public function isLoaded(): bool
{
return $this->loaded;
}
Expand All @@ -387,7 +386,7 @@ public function isLoaded()
*
* @return boolean
*/
public function areAmountsLoaded()
public function areAmountsLoaded(): bool
{
return $this->amounts_loaded;
}
Expand All @@ -399,20 +398,20 @@ public function areAmountsLoaded()
*
* @return void
*/
public function setId($id)
public function setId(string $id): void
{
$this->id = $id;
}

/**
* Set new prices
*
* @param array $ids array of identifier
* @param array $amounts array of amounts
* @param array<int, string> $ids array of identifier
* @param array<int, string> $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) {
Expand All @@ -427,19 +426,19 @@ public function setPrices($ids, $amounts)
*
* @return boolean
*/
public function isInactive($id)
public function isInactive(int $id): bool
{
return in_array($id, $this->inactives);
}

/**
* Set inactives types
*
* @param array $inactives array of inactives types
* @param array<int, string> $inactives array of inactives types
*
* @return void
*/
public function setInactives($inactives)
public function setInactives(array $inactives): void
{
$this->inactives = $inactives;
}
Expand All @@ -449,7 +448,7 @@ public function setInactives($inactives)
*
* @return void
*/
public function unsetInactives()
public function unsetInactives(): void
{
$this->inactives = array();
}
Expand Down
32 changes: 16 additions & 16 deletions lib/GalettePaypal/PaypalHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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>|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 {
Expand Down Expand Up @@ -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;
Expand All @@ -148,17 +148,17 @@ protected function getTableName($prefixed = false)
*
* @return string
*/
protected function getPk()
protected function getPk(): string
{
return self::PK;
}

/**
* Gets Paypal history
*
* @return array
* @return array<int, object>
*/
public function getPaypalHistory()
public function getPaypalHistory(): array
{
$orig = $this->getHistory();
$new = array();
Expand Down Expand Up @@ -210,9 +210,9 @@ function ($match) {
/**
* Builds the order clause
*
* @return string SQL ORDER clause
* @return array<int, string> SQL ORDER clause
*/
protected function buildOrderClause()
protected function buildOrderClause(): array
{
$order = array();

Expand Down
Loading

0 comments on commit 6e1db6b

Please sign in to comment.