diff --git a/acp/boardrules_info.php b/acp/boardrules_info.php index 13af2932..f222f6ed 100644 --- a/acp/boardrules_info.php +++ b/acp/boardrules_info.php @@ -12,6 +12,11 @@ class boardrules_info { + /** + * Return ACP module configuration. + * + * @return array + */ public function module() { return array( diff --git a/acp/boardrules_module.php b/acp/boardrules_module.php index d2399dc6..ed81755e 100644 --- a/acp/boardrules_module.php +++ b/acp/boardrules_module.php @@ -12,8 +12,13 @@ class boardrules_module { + /** @var string */ public $page_title; + + /** @var string */ public $tpl_name; + + /** @var string */ public $u_action; /** @@ -21,6 +26,7 @@ class boardrules_module * * @param int $id * @param string $mode + * @return void * @throws \Exception */ public function main($id, $mode) diff --git a/controller/admin_controller.php b/controller/admin_controller.php index 9ba50cb4..f62c447a 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -239,6 +239,7 @@ public function display_language_dashboard() * @param int $parent_id Category to display rules from; default: 0 * @return void * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function display_rules($language, $parent_id = 0) { @@ -295,7 +296,7 @@ public function display_rules($language, $parent_id = 0) $this->template->assign_block_vars('breadcrumb', array( 'RULE_TITLE' => $entity->get_title(), - 'S_CURRENT_LEVEL' => $entity->get_id() == $parent_id, + 'S_CURRENT_LEVEL' => $entity->get_id() === (int) $parent_id, 'U_RULE' => "{$this->u_action}&language={$language}&parent_id=" . $entity->get_id(), )); @@ -405,7 +406,7 @@ public function copy_ruleset($target_language, $return_to = '') { $copy_result = $this->ruleset_operator->copy($source_language, $target_language); } - catch (\InvalidArgumentException | \RuntimeException $e) + catch (\Exception $e) { trigger_error($this->lang->lang($e->getMessage()) . adm_back_link($return_url), E_USER_WARNING); } @@ -508,6 +509,7 @@ protected function get_ruleset_return_url($language, $return_to) * @param int $parent_id Category to display rules from; default: 0 * @return void * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function add_rule($language, $parent_id = 0) { @@ -548,6 +550,7 @@ public function add_rule($language, $parent_id = 0) * @param int $rule_id The rule identifier to edit * @return void * @access public + * @throws \phpbb\boardrules\exception\base If the rule does not exist or stored rule data is invalid */ public function edit_rule($rule_id) { @@ -590,6 +593,7 @@ public function edit_rule($rule_id) * @param array $data The form data to be processed * @return void * @access protected + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ protected function add_edit_rule_data($entity, $data) { @@ -686,7 +690,7 @@ protected function add_edit_rule_data($entity, $data) } // Change rule parent - if (isset($data['rule_parent_id']) && ($data['rule_parent_id'] != $entity->get_parent_id())) + if (isset($data['rule_parent_id']) && ($entity->get_parent_id() !== (int) $data['rule_parent_id'])) { try { @@ -765,6 +769,7 @@ protected function add_edit_rule_data($entity, $data) * @param int $rule_id The rule identifier to delete * @return void * @access public + * @throws \phpbb\boardrules\exception\out_of_bounds If the rule does not exist */ public function delete_rule($rule_id) { @@ -813,6 +818,7 @@ public function delete_rule($rule_id) * @param int $amount The number of places to move the rule * @return void * @access public + * @throws \phpbb\boardrules\exception\out_of_bounds If the rule does not exist after moving */ public function move_rule($rule_id, $direction, $amount = 1) { @@ -955,13 +961,14 @@ protected function has_copy_source(array $languages, $target_language) } /** - * Build pull down menu options of available rule parents - * - * @param \phpbb\boardrules\entity\rule_interface $entity The rule entity object - * @param int $parent_id Category to display rules from; default: 0 - * @return void - * @access protected - */ + * Build pull down menu options of available rule parents + * + * @param \phpbb\boardrules\entity\rule_interface $entity The rule entity object + * @param int $parent_id Category to display rules from; default: 0 + * @return void + * @access protected + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid + */ protected function build_parent_select_menu($entity, $parent_id = 0) { // Prepare rule pull-down field @@ -992,8 +999,8 @@ protected function build_parent_select_menu($entity, $parent_id = 0) 'RULE_ID' => $rule_menu_item->get_id(), 'RULE_TITLE' => $padding . $rule_menu_item->get_title(), - 'S_DISABLED' => ($rule_menu_item->get_left_id() > $entity->get_left_id() && $rule_menu_item->get_right_id() < $entity->get_right_id()) || $rule_menu_item->get_id() == $entity->get_id(), - 'S_RULE_PARENT' => $rule_menu_item->get_id() == $parent_id, + 'S_DISABLED' => ($rule_menu_item->get_left_id() > $entity->get_left_id() && $rule_menu_item->get_right_id() < $entity->get_right_id()) || $rule_menu_item->get_id() === $entity->get_id(), + 'S_RULE_PARENT' => $rule_menu_item->get_id() === (int) $parent_id, )); } } diff --git a/controller/admin_interface.php b/controller/admin_interface.php index 05004850..9071ec57 100644 --- a/controller/admin_interface.php +++ b/controller/admin_interface.php @@ -59,6 +59,7 @@ public function set_ruleset_published($language, $published, $return_to = ''); * @param int $parent_id Category to display rules from; default: 0 * @return void * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function display_rules($language, $parent_id = 0); @@ -77,6 +78,7 @@ public function save_ruleset_intro($language); * @param int $parent_id Category to display rules from; default: 0 * @return void * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function add_rule($language, $parent_id = 0); @@ -86,6 +88,7 @@ public function add_rule($language, $parent_id = 0); * @param int $rule_id The rule identifier to edit * @return void * @access public + * @throws \phpbb\boardrules\exception\base If the rule does not exist or stored rule data is invalid */ public function edit_rule($rule_id); @@ -95,6 +98,7 @@ public function edit_rule($rule_id); * @param int $rule_id The rule identifier to delete * @return void * @access public + * @throws \phpbb\boardrules\exception\out_of_bounds If the rule does not exist */ public function delete_rule($rule_id); @@ -106,6 +110,7 @@ public function delete_rule($rule_id); * @param int $amount The number of places to move the rule * @return void * @access public + * @throws \phpbb\boardrules\exception\out_of_bounds If the rule does not exist after moving */ public function move_rule($rule_id, $direction, $amount = 1); diff --git a/controller/main_controller.php b/controller/main_controller.php index 2a30e8ed..15b548ab 100644 --- a/controller/main_controller.php +++ b/controller/main_controller.php @@ -74,6 +74,7 @@ public function __construct(\phpbb\config\config $config, \phpbb\controller\help * * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function display() { @@ -176,7 +177,7 @@ public function display() } // Assign values to template vars for the rules page - $intro_text = (string) $this->ruleset_operator->get_intro_text($display_language); + $intro_text = $this->ruleset_operator->get_intro_text($display_language); $this->template->assign_vars(array( 'S_BOARD_RULES' => true, diff --git a/controller/main_interface.php b/controller/main_interface.php index 6717cd49..44c242ec 100644 --- a/controller/main_interface.php +++ b/controller/main_interface.php @@ -22,6 +22,7 @@ interface main_interface * * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function display(); } diff --git a/entity/rule.php b/entity/rule.php index 5deeb93d..87b951ef 100644 --- a/entity/rule.php +++ b/entity/rule.php @@ -348,7 +348,7 @@ public function set_message($message) /** * Check if bbcode is enabled on the message * - * @return int + * @return int OPTION_FLAG_BBCODE when enabled, otherwise 0 * @access public */ public function message_bbcode_enabled() @@ -385,7 +385,7 @@ public function message_disable_bbcode() /** * Check if magic_url is enabled on the message * - * @return int + * @return int OPTION_FLAG_LINKS when enabled, otherwise 0 * @access public */ public function message_magic_url_enabled() @@ -422,7 +422,7 @@ public function message_disable_magic_url() /** * Check if smilies are enabled on the message * - * @return int + * @return int OPTION_FLAG_SMILIES when enabled, otherwise 0 * @access public */ public function message_smilies_enabled() diff --git a/entity/rule_interface.php b/entity/rule_interface.php index a23dffbf..d687bf69 100644 --- a/entity/rule_interface.php +++ b/entity/rule_interface.php @@ -120,7 +120,7 @@ public function set_message($message); /** * Check if bbcode is enabled on the message * - * @return bool + * @return int OPTION_FLAG_BBCODE when enabled, otherwise 0 * @access public */ public function message_bbcode_enabled(); @@ -144,7 +144,7 @@ public function message_disable_bbcode(); /** * Check if magic_url is enabled on the message * - * @return bool + * @return int OPTION_FLAG_LINKS when enabled, otherwise 0 * @access public */ public function message_magic_url_enabled(); @@ -168,7 +168,7 @@ public function message_disable_magic_url(); /** * Check if smilies are enabled on the message * - * @return bool + * @return int OPTION_FLAG_SMILIES when enabled, otherwise 0 * @access public */ public function message_smilies_enabled(); @@ -221,6 +221,7 @@ public function get_language(); * @param string $language language iso * @return rule_interface $this object for chaining calls; load()->set()->save() * @access public + * @throws \phpbb\boardrules\exception\unexpected_value If the language is not installed */ public function set_language($language); diff --git a/migrations/helper.php b/migrations/helper.php index b1c573e5..c4ebb8e6 100644 --- a/migrations/helper.php +++ b/migrations/helper.php @@ -47,6 +47,7 @@ public function __construct(\phpbb\db\driver\driver_interface $db, $table_prefix * * @param string $new_column Name of the column to be updated * @param string $old_column Name of the column with old data + * @return void */ public function change_rule_language($new_column, $old_column) { diff --git a/migrations/v20x/m15_update_lang_schema.php b/migrations/v20x/m15_update_lang_schema.php index 1708c776..530a59d7 100644 --- a/migrations/v20x/m15_update_lang_schema.php +++ b/migrations/v20x/m15_update_lang_schema.php @@ -78,6 +78,8 @@ public function update_data() /** * Change rule_language values from lang_id to lang_iso + * + * @return void */ public function change_rule_language() { diff --git a/migrations/v20x/m16_update_lang_postgres.php b/migrations/v20x/m16_update_lang_postgres.php index 20cb09f1..f673ba16 100644 --- a/migrations/v20x/m16_update_lang_postgres.php +++ b/migrations/v20x/m16_update_lang_postgres.php @@ -52,6 +52,7 @@ public function update_data() * To work around this, we re-create a new rule_language column with * the new data type and copy the new data to it via specific queries. * + * @return void * @throws \RuntimeException */ public function alter_rule_language() diff --git a/migrations/v30x/m18_ruleset_status.php b/migrations/v30x/m18_ruleset_status.php index e0be345e..916e6d7f 100644 --- a/migrations/v30x/m18_ruleset_status.php +++ b/migrations/v30x/m18_ruleset_status.php @@ -12,11 +12,17 @@ class m18_ruleset_status extends \phpbb\db\migration\migration { + /** + * {@inheritdoc} + */ public function effectively_installed() { return $this->db_tools->sql_table_exists($this->table_prefix . 'boardrules_rulesets'); } + /** + * {@inheritdoc} + */ public static function depends_on() { return array( @@ -25,6 +31,9 @@ public static function depends_on() ); } + /** + * {@inheritdoc} + */ public function update_schema() { return array( @@ -41,6 +50,9 @@ public function update_schema() ); } + /** + * {@inheritdoc} + */ public function revert_schema() { return array( diff --git a/migrations/v30x/m19_list_style_options.php b/migrations/v30x/m19_list_style_options.php index 6aca7453..0547e159 100644 --- a/migrations/v30x/m19_list_style_options.php +++ b/migrations/v30x/m19_list_style_options.php @@ -12,11 +12,17 @@ class m19_list_style_options extends \phpbb\db\migration\migration { + /** + * {@inheritdoc} + */ public function effectively_installed() { return $this->config['boardrules_list_style'] !== 'disc'; } + /** + * {@inheritdoc} + */ public static function depends_on() { return array( @@ -25,6 +31,9 @@ public static function depends_on() ); } + /** + * {@inheritdoc} + */ public function update_data() { return array( @@ -32,6 +41,9 @@ public function update_data() ); } + /** + * {@inheritdoc} + */ public function revert_data() { return array( diff --git a/operators/rule.php b/operators/rule.php index 0ed1329f..c7c7fb25 100644 --- a/operators/rule.php +++ b/operators/rule.php @@ -50,8 +50,9 @@ public function __construct(ContainerInterface $container, \phpbb\boardrules\ope * * @param string $language Language selection iso * @param int $parent_id Category to display rules from; default: 0 - * @return array Array of rule data entities + * @return \phpbb\boardrules\entity\rule_interface[] Rule entities * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function get_rules($language, $parent_id = 0) { @@ -81,6 +82,7 @@ public function get_rules($language, $parent_id = 0) * @param int $parent_id Category to display rules from; default: 0 * @return \phpbb\boardrules\entity\rule_interface Added rule entity * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function add_rule($entity, $language, $parent_id = 0) @@ -122,6 +124,7 @@ public function add_rule($entity, $language, $parent_id = 0) * @param int $rule_id The rule identifier to delete * @return void * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function delete_rule($rule_id) @@ -147,6 +150,7 @@ public function delete_rule($rule_id) * @param int $amount The number of places to move the rule * @return void * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function move($rule_id, $direction = 'up', $amount = 1) @@ -172,6 +176,7 @@ public function move($rule_id, $direction = 'up', $amount = 1) * @param int $new_parent_id The new rule parent identifier * @return void * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function change_parent($rule_id, $new_parent_id) @@ -197,8 +202,9 @@ public function change_parent($rule_id, $new_parent_id) * * @param string $language Language selection iso * @param int $parent_id Category to display rules from - * @return array Array of rule data for a rule's parent rules + * @return \phpbb\boardrules\entity\rule_interface[] Parent rule entities * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function get_rule_parents($language, $parent_id) { diff --git a/operators/rule_interface.php b/operators/rule_interface.php index 92616ec1..c8fd252e 100644 --- a/operators/rule_interface.php +++ b/operators/rule_interface.php @@ -22,8 +22,9 @@ interface rule_interface * * @param string $language Language selection iso * @param int $parent_id Category to display rules from; default: 0 - * @return array Array of rule data entities + * @return \phpbb\boardrules\entity\rule_interface[] Rule entities * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function get_rules($language, $parent_id = 0); @@ -33,8 +34,10 @@ public function get_rules($language, $parent_id = 0); * @param \phpbb\boardrules\entity\rule_interface $entity Rule entity with new data to insert * @param string $language Language selection iso * @param int $parent_id Category to display rules from; default: 0 - * @return rule_interface Added rule entity + * @return \phpbb\boardrules\entity\rule_interface Added rule entity * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired + * @throws \phpbb\boardrules\exception\out_of_bounds If the entity was already inserted */ public function add_rule($entity, $language, $parent_id = 0); @@ -44,6 +47,7 @@ public function add_rule($entity, $language, $parent_id = 0); * @param int $rule_id The rule identifier to delete * @return void * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function delete_rule($rule_id); @@ -56,6 +60,7 @@ public function delete_rule($rule_id); * @param int $amount The number of places to move the rule * @return void * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function move($rule_id, $direction, $amount = 1); @@ -67,6 +72,7 @@ public function move($rule_id, $direction, $amount = 1); * @param int $new_parent_id The new rule parent identifier * @return void * @access public + * @throws \RuntimeException If the nested-set lock cannot be acquired * @throws \phpbb\boardrules\exception\out_of_bounds */ public function change_parent($rule_id, $new_parent_id); @@ -76,8 +82,9 @@ public function change_parent($rule_id, $new_parent_id); * * @param string $language Language selection iso * @param int $parent_id Category to display rules from - * @return array Array of rule data for a rule's parent rules + * @return \phpbb\boardrules\entity\rule_interface[] Parent rule entities * @access public + * @throws \phpbb\boardrules\exception\base If stored rule data is invalid */ public function get_rule_parents($language, $parent_id); } diff --git a/operators/ruleset_interface.php b/operators/ruleset_interface.php index dee30f03..cde55980 100644 --- a/operators/ruleset_interface.php +++ b/operators/ruleset_interface.php @@ -25,7 +25,9 @@ public function get_languages(); * @param string $source_language * @param string $target_language * @return array Copy result containing rule and renamed-anchor counts - * @throws \Exception + * @throws \InvalidArgumentException If either language is invalid or source ruleset is empty + * @throws \RuntimeException If nested-set lock cannot be acquired + * @throws \Exception If ruleset persistence fails */ public function copy($source_language, $target_language); @@ -55,6 +57,7 @@ public function get_intro_text($language); * @param string $language * @param string $intro_text * @return void + * @throws \InvalidArgumentException If the language is not installed */ public function set_intro_text($language, $intro_text); @@ -64,6 +67,7 @@ public function set_intro_text($language, $intro_text); * @param string $language * @param bool $published * @return void + * @throws \InvalidArgumentException If the language is not installed or its ruleset is empty */ public function set_published($language, $published); } diff --git a/tests/controller/admin_controller_test.php b/tests/controller/admin_controller_test.php index e3f437ad..55a092ea 100644 --- a/tests/controller/admin_controller_test.php +++ b/tests/controller/admin_controller_test.php @@ -420,6 +420,28 @@ public function test_copy_ruleset_translates_operator_error(): void $this->controller->copy_ruleset('fr'); } + public function test_copy_ruleset_handles_general_operator_exception(): void + { + $ruleset_operator = $this->getMockBuilder(\phpbb\boardrules\operators\ruleset::class) + ->disableOriginalConstructor() + ->setMethods(array('get_languages', 'copy')) + ->getMock(); + $ruleset_operator->method('get_languages')->willReturn(array( + array('lang_iso' => 'en', 'lang_local_name' => 'English', 'rule_count' => 3), + array('lang_iso' => 'fr', 'lang_local_name' => 'Français', 'rule_count' => 0), + )); + $ruleset_operator->expects(self::once()) + ->method('copy') + ->with('en', 'fr') + ->willThrowException(new \Exception('ACP_BOARDRULES_COPY_FAILED')); + $this->replace_controller_service('ruleset_operator', $ruleset_operator); + $this->post['submit'] = true; + $this->variables['source_language'] = 'en'; + $this->setExpectedTriggerError(E_USER_WARNING, 'ACP_BOARDRULES_COPY_FAILED'); + + $this->controller->copy_ruleset('fr'); + } + public function test_copy_ruleset_rejects_invalid_form(): void { admin_test_state::$valid_form = false; diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index ab9f862c..5d80cb84 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -70,11 +70,13 @@ protected function setUp(): void { return array('_route' => 'phpbb_boardrules_main_controller'); } - else if ($path === '/runtime-error') + + if ($path === '/runtime-error') { throw new \RuntimeException('Unable to match route.'); } - else if ($path === '/missing-route-name') + + if ($path === '/missing-route-name') { return array(); }