From 374a36a85bd389b413b5ce857f53250ead4e22ec Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 4 Nov 2023 21:03:28 +0100 Subject: [PATCH] code review --- src/BackendBehaviors.php | 39 +++++++++++-------- src/ManageVars.php | 84 +++++++++++++++++++++++++++++++++------- src/My.php | 8 ++-- src/Utils.php | 22 ++++++----- 4 files changed, 109 insertions(+), 44 deletions(-) diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 589c903..a032235 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -40,6 +40,11 @@ use Exception; */ class BackendBehaviors { + /** + * Periods combo. + * + * @var array $combo_period + */ private static array $combo_period = []; /** @@ -91,7 +96,7 @@ class BackendBehaviors /** * User pref for periods columns lists. * - * @param ArrayObject $cols Columns + * @param ArrayObject $cols Columns */ public static function adminColumnsListsV2(ArrayObject $cols): void { @@ -112,7 +117,7 @@ class BackendBehaviors /** * User pref periods filters options. * - * @param ArrayObject $sorts Sort options + * @param ArrayObject $sorts Sort options */ public static function adminFiltersListsV2(ArrayObject $sorts): void { @@ -128,8 +133,8 @@ class BackendBehaviors /** * Add columns period to posts list header. * - * @param MetaRecord $rs record instance - * @param ArrayObject $cols Columns + * @param MetaRecord $rs Record instance + * @param ArrayObject $cols Columns */ public static function adminPostListHeaderV2(MetaRecord $rs, ArrayObject $cols): void { @@ -141,8 +146,8 @@ class BackendBehaviors /** * Add columns period to posts list values. * - * @param MetaRecord $rs record instance - * @param ArrayObject $cols Columns + * @param MetaRecord $rs Record instance + * @param ArrayObject $cols Columns */ public static function adminPostListValueV2(MetaRecord $rs, ArrayObject $cols): void { @@ -225,8 +230,8 @@ class BackendBehaviors /** * Posts actions callback to remove period. * - * @param ActionsPosts $pa ActionsPosts instance - * @param ArrayObject $post _POST actions + * @param ActionsPosts $pa ActionsPosts instance + * @param ArrayObject $post _POST actions */ public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void { @@ -246,7 +251,7 @@ class BackendBehaviors // Remove linked period foreach ($posts_ids as $post_id) { - self::delPeriod($post_id); + self::delPeriod((int) $post_id); } Notices::addSuccessNotice(__('Posts have been removed from periodical.')); @@ -256,8 +261,8 @@ class BackendBehaviors /** * Posts actions callback to add period. * - * @param ActionsPosts $pa ActionsPosts instance - * @param ArrayObject $post _POST actions + * @param ActionsPosts $pa ActionsPosts instance + * @param ArrayObject $post _POST actions */ public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void { @@ -272,8 +277,8 @@ class BackendBehaviors // Save action if (!empty($post['periodical'])) { foreach ($posts_ids as $post_id) { - self::delPeriod($post_id); - self::addPeriod($post_id, (int) $post['periodical']); + self::delPeriod((int) $post_id); + self::addPeriod((int) $post_id, (int) $post['periodical']); } Notices::addSuccessNotice(__('Posts have been added to periodical.')); @@ -309,9 +314,9 @@ class BackendBehaviors /** * Add form to post sidebar. * - * @param ArrayObject $main_items Main items - * @param ArrayObject $sidebar_items Sidebar items - * @param null|MetaRecord $post Post record or null + * @param ArrayObject $main_items Main items + * @param ArrayObject $sidebar_items Sidebar items + * @param null|MetaRecord $post Post record or null */ public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void { @@ -365,7 +370,7 @@ class BackendBehaviors /** * Combo of available periods. * - * @return array List of period + * @return array List of period */ private static function comboPeriod(): array { diff --git a/src/ManageVars.php b/src/ManageVars.php index 09ed35a..693f881 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -13,46 +13,102 @@ namespace Dotclear\Plugin\periodical; */ class ManageVars { - /** @var ManageVars $container Self instance */ + /** + * Self instance. + * + * @var ManageVars $container + */ private static $container; - /** @var string $action The post form action */ + /** + * The post form action. + * + * @var string $action + */ public readonly string $action; - /** @var string $redir The post form redirection */ + /** + * The post form redirection. + * + * @var string $redir + */ public readonly string $redir; - /** @var array $periods The post form periods */ + /** + * The post form periods. + * + * @var array $periods + */ public readonly array $periods; - /** @var array $entries The post form entries */ + /** + * The post form entries. + * + * @var array $entries + */ public readonly array $entries; - /** @var null|int $period_id The post form period id */ + /** + * The post form period id. + * + * @var null|int $period_id + */ public readonly ?int $period_id; - /** @var string $period_title The psort form period title */ + /** + * The psort form period title. + * + * @var string $period_title + */ public readonly string $period_title; - /** @var int $period_pub_nb The post form period publication number */ + /** + * The post form period publication number. + * + * @var int $period_pub_nb + */ public readonly int $period_pub_nb; - /** @var string $period_pub_int The post form period publication interval */ + /** + * The post form period publication interval. + * + * @var string $period_pub_int + */ public readonly string $period_pub_int; - /** @var string $period_curdt The post form period current date */ + /** + * The post form period current date. + * + * @var string $period_curdt + */ public readonly string $period_curdt; - /** @var string $period_curdt The post form period end date */ + /** + * The post form period end date. + * + * @var string $period_curdt + */ public readonly string $period_enddt; - /** @var bool $bad_period_id Is period ID wrong */ + /** + * Is period ID wrong . + * + * @var bool $bad_period_id + */ public readonly bool $bad_period_id; - /** @var bool $bad_period_curdt Is period current date wrong */ + /** + * Is period current date wrong. + * + * @var bool $bad_period_curdt + */ public readonly bool $bad_period_curdt; - /** @var bool $bad_period_enddt Is period end date wrong */ + /** + * Is period end date wrong. + * + * @var bool $bad_period_enddt + */ public readonly bool $bad_period_enddt; /** diff --git a/src/My.php b/src/My.php index d85867b..8414acc 100644 --- a/src/My.php +++ b/src/My.php @@ -33,7 +33,7 @@ class My extends MyPlugin /** * Periods action combo. * - * @return array + * @return array */ public static function periodsActionCombo(): array { @@ -46,7 +46,7 @@ class My extends MyPlugin /** * Period entries action combo. * - * @return array + * @return array> */ public static function entriesActionsCombo(): array { @@ -64,7 +64,7 @@ class My extends MyPlugin /** * Periods sortby combo. * - * @return array + * @return array */ public static function sortbyCombo(): array { @@ -78,7 +78,7 @@ class My extends MyPlugin /** * Period combo. * - * @return array + * @return array */ public static function periodCombo(): array { diff --git a/src/Utils.php b/src/Utils.php index 7838313..f824cfb 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -30,8 +30,12 @@ use Exception; */ class Utils { - /** @var null|string $lock File lock for update */ - private static $lock = null; + /** + * File lock for update. + * + * @var null|string $lock + */ + private static ?string $lock = null; /** * Get periodical table cursor. @@ -46,9 +50,9 @@ class Utils /** * Get periods. * - * @param array|ArrayObject $params Parameters - * @param bool $count_only Only counts results - * @param SelectStatement $ext_sql Optional SelectStatement instance + * @param array|ArrayObject $params Parameters + * @param bool $count_only Only counts results + * @param SelectStatement $ext_sql Optional SelectStatement instance * * @return MetaRecord A record with some more capabilities */ @@ -234,9 +238,9 @@ class Utils /** * Get posts related to periods. * - * @param array|ArrayObject $params Parameters - * @param bool $count_only Only counts results - * @param SelectStatement $ext_sql Optional SelectStatement instance + * @param array|ArrayObject $params Parameters + * @param bool $count_only Only counts results + * @param SelectStatement $ext_sql Optional SelectStatement instance * * @return MetaRecord A record with some more capabilities */ @@ -304,7 +308,7 @@ class Utils $sql->and('P.post_status = ' . App::blog()::POST_PENDING); } - return App::blog()->getPosts($params, $count_only, $sql) ?? MetaRecord::newFromArray([]); + return App::blog()->getPosts($params, $count_only, $sql); } /**