Skip to content

Commit df382e1

Browse files
authored
Merge pull request #347 from iMattPro/fixes
Fix missing role install issues and code inspections
2 parents 7c62a44 + 9bdeaa2 commit df382e1

23 files changed

Lines changed: 83 additions & 100 deletions

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "phpbb/boardrules",
33
"type": "phpbb-extension",
44
"description": "An extension which allows you to create a set of rules for your phpBB forum",
5-
"homepage": "https://www.phpbb.com",
5+
"homepage": "https://www.phpbb.com/customise/db/extension/boardrules/",
66
"version": "2.1.3",
77
"keywords": ["phpbb", "extension", "rules"],
88
"license": "GPL-2.0-only",
@@ -29,7 +29,7 @@
2929
}
3030
],
3131
"require": {
32-
"php": ">=5.4",
32+
"php": ">=7.1.3",
3333
"composer/installers": "~1.0"
3434
},
3535
"require-dev": {
@@ -38,7 +38,7 @@
3838
"extra": {
3939
"display-name": "Board Rules",
4040
"soft-require": {
41-
"phpbb/phpbb": ">=3.2.0"
41+
"phpbb/phpbb": ">=3.3.2"
4242
},
4343
"version-check": {
4444
"host": "www.phpbb.com",

controller/admin_controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ protected function add_edit_rule_data($entity, $data)
444444
}
445445

446446
// Do not allow an empty rule title
447-
if ($entity->get_title() == '')
447+
if ($entity->get_title() === '')
448448
{
449449
$errors[] = $this->lang->lang('ACP_RULE_TITLE_EMPTY');
450450
}
@@ -713,7 +713,7 @@ protected function build_parent_select_menu($entity, $parent_id = 0)
713713
}
714714
else if ($rule_menu_item->get_left_id() > $right + 1)
715715
{
716-
$padding = isset($padding_store[$rule_menu_item->get_parent_id()]) ? $padding_store[$rule_menu_item->get_parent_id()] : '';
716+
$padding = $padding_store[$rule_menu_item->get_parent_id()] ?? '';
717717
}
718718

719719
$right = $rule_menu_item->get_right_id();

entity/rule.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function set_title($title)
274274
$title = (string) $title;
275275

276276
// We limit the title length to 200 characters
277-
if (truncate_string($title, 200) != $title)
277+
if (truncate_string($title, 200) !== $title)
278278
{
279279
throw new \phpbb\boardrules\exception\unexpected_value(array('title', 'TOO_LONG'));
280280
}
@@ -294,8 +294,8 @@ public function set_title($title)
294294
public function get_message_for_edit()
295295
{
296296
// Use defaults if these haven't been set yet
297-
$message = isset($this->data['rule_message']) ? $this->data['rule_message'] : '';
298-
$uid = isset($this->data['rule_message_bbcode_uid']) ? $this->data['rule_message_bbcode_uid'] : '';
297+
$message = $this->data['rule_message'] ?? '';
298+
$uid = $this->data['rule_message_bbcode_uid'] ?? '';
299299
$options = isset($this->data['rule_message_bbcode_options']) ? (int) $this->data['rule_message_bbcode_options'] : 0;
300300

301301
// Generate for edit
@@ -314,9 +314,9 @@ public function get_message_for_edit()
314314
public function get_message_for_display($censor_text = true)
315315
{
316316
// If these haven't been set yet; use defaults
317-
$message = isset($this->data['rule_message']) ? $this->data['rule_message'] : '';
318-
$uid = isset($this->data['rule_message_bbcode_uid']) ? $this->data['rule_message_bbcode_uid'] : '';
319-
$bitfield = isset($this->data['rule_message_bbcode_bitfield']) ? $this->data['rule_message_bbcode_bitfield'] : '';
317+
$message = $this->data['rule_message'] ?? '';
318+
$uid = $this->data['rule_message_bbcode_uid'] ?? '';
319+
$bitfield = $this->data['rule_message_bbcode_bitfield'] ?? '';
320320
$options = isset($this->data['rule_message_bbcode_options']) ? (int) $this->data['rule_message_bbcode_options'] : 0;
321321

322322
// Generate for display
@@ -481,13 +481,13 @@ public function set_anchor($anchor)
481481
$anchor = (string) $anchor;
482482

483483
// Anchor should not contain any special characters
484-
if (($anchor != '') && !preg_match('/^[^!"#$%&*\'()+,.\/\\\\:;<=>?@\[\]^`{|}~ ]*$/', $anchor))
484+
if (($anchor !== '') && !preg_match('/^[^!"#$%&*\'()+,.\/\\\\:;<=>?@\[\]^`{|}~ ]*$/', $anchor))
485485
{
486486
throw new \phpbb\boardrules\exception\unexpected_value(array('anchor', 'ILLEGAL_CHARACTERS'));
487487
}
488488

489489
// We limit the anchor length to 255 characters
490-
if (truncate_string($anchor, 255) != $anchor)
490+
if (truncate_string($anchor, 255) !== $anchor)
491491
{
492492
throw new \phpbb\boardrules\exception\unexpected_value(array('anchor', 'TOO_LONG'));
493493
}
@@ -526,7 +526,7 @@ public function set_anchor($anchor)
526526
*/
527527
public function get_language()
528528
{
529-
return isset($this->data['rule_language']) ? $this->data['rule_language'] : '';
529+
return $this->data['rule_language'] ?? '';
530530
}
531531

532532
/**
@@ -608,7 +608,7 @@ public function get_right_id()
608608
protected function set_message_option($option_value, $negate = false, $reparse_message = true)
609609
{
610610
// Set rule_message_bbcode_options to 0 if it does not yet exist
611-
$this->data['rule_message_bbcode_options'] = isset($this->data['rule_message_bbcode_options']) ? $this->data['rule_message_bbcode_options'] : 0;
611+
$this->data['rule_message_bbcode_options'] = $this->data['rule_message_bbcode_options'] ?? 0;
612612

613613
// If we're setting the option and the option is not already set
614614
if (!$negate && !($this->data['rule_message_bbcode_options'] & $option_value))

exception/base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class base extends \Exception
2828
*
2929
* Different from normal exceptions in that we do not enforce $message to be a string.
3030
*
31-
* @param string|array $message
31+
* @param string|array|null $message
3232
* @param int $code
33-
* @param \Exception $previous
33+
* @param \Exception|null $previous
3434
* @access public
3535
*/
3636
public function __construct($message = null, $code = 0, \Exception $previous = null)

ext.php

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,116 +19,94 @@
1919
* enable_step(), disable_step() and purge_step(). As it is, these methods are defined
2020
* in phpbb_extension_base, which this class extends, but you can overwrite them to
2121
* give special instructions for those cases. Board Rules must do this because it uses
22-
* the notifications system, which requires the methods enable_notifications(),
22+
* the notifications' system, which requires the methods enable_notifications(),
2323
* disable_notifications() and purge_notifications() be run to properly manage the
2424
* notifications created by Board Rules when enabling, disabling or deleting this
2525
* extension.
2626
*/
2727
class ext extends \phpbb\extension\base
2828
{
2929
/**
30-
* Check whether or not the extension can be enabled.
30+
* Check whether the extension can be enabled.
3131
* The current phpBB version should meet or exceed
3232
* the minimum version required by this extension:
3333
*
34-
* Requires phpBB 3.2.0 due to new faq controller route for bbcodes,
35-
* the revised notifications system, font awesome and the text reparser.
34+
* Requires phpBB 3.3.2 due to using role_exists check in permission migration.
3635
*
3736
* @return bool
3837
* @access public
3938
*/
4039
public function is_enableable()
4140
{
42-
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=');
41+
return phpbb_version_compare(PHPBB_VERSION, '3.3.2', '>=');
4342
}
4443

4544
/**
4645
* Overwrite enable_step to enable board rules notifications
4746
* before any included migrations are installed.
4847
*
4948
* @param mixed $old_state State returned by previous call of this method
50-
* @return mixed Returns false after last step, otherwise temporary state
49+
* @return bool|string Returns false after last step, otherwise temporary state
5150
* @access public
5251
*/
5352
public function enable_step($old_state)
5453
{
55-
switch ($old_state)
54+
// if nothing has run yet
55+
if ($old_state === false)
5656
{
57-
case '': // Empty means nothing has run yet
58-
59-
// Enable board rules notifications
60-
$phpbb_notifications = $this->container->get('notification_manager');
61-
$phpbb_notifications->enable_notifications('phpbb.boardrules.notification.type.boardrules');
62-
return 'notifications';
63-
64-
break;
65-
66-
default:
67-
68-
// Run parent enable step method
69-
return parent::enable_step($old_state);
70-
71-
break;
57+
// Enable board rules notifications
58+
$phpbb_notifications = $this->container->get('notification_manager');
59+
$phpbb_notifications->enable_notifications('phpbb.boardrules.notification.type.boardrules');
60+
return 'notifications';
7261
}
62+
63+
// Run parent enable step method
64+
return parent::enable_step($old_state);
7365
}
7466

7567
/**
7668
* Overwrite disable_step to disable board rules notifications
7769
* before the extension is disabled.
7870
*
7971
* @param mixed $old_state State returned by previous call of this method
80-
* @return mixed Returns false after last step, otherwise temporary state
72+
* @return bool|string Returns false after last step, otherwise temporary state
8173
* @access public
8274
*/
8375
public function disable_step($old_state)
8476
{
85-
switch ($old_state)
77+
// if nothing has run yet
78+
if ($old_state === false)
8679
{
87-
case '': // Empty means nothing has run yet
88-
89-
// Disable board rules notifications
90-
$phpbb_notifications = $this->container->get('notification_manager');
91-
$phpbb_notifications->disable_notifications('phpbb.boardrules.notification.type.boardrules');
92-
return 'notifications';
93-
94-
break;
95-
96-
default:
97-
98-
// Run parent disable step method
99-
return parent::disable_step($old_state);
100-
101-
break;
80+
// Disable board rules notifications
81+
$phpbb_notifications = $this->container->get('notification_manager');
82+
$phpbb_notifications->disable_notifications('phpbb.boardrules.notification.type.boardrules');
83+
return 'notifications';
10284
}
85+
86+
// Run parent disable step method
87+
return parent::disable_step($old_state);
10388
}
10489

10590
/**
10691
* Overwrite purge_step to purge board rules notifications before
10792
* any included and installed migrations are reverted.
10893
*
10994
* @param mixed $old_state State returned by previous call of this method
110-
* @return mixed Returns false after last step, otherwise temporary state
95+
* @return bool|string Returns false after last step, otherwise temporary state
11196
* @access public
11297
*/
11398
public function purge_step($old_state)
11499
{
115-
switch ($old_state)
100+
// if nothing has run yet
101+
if ($old_state === false)
116102
{
117-
case '': // Empty means nothing has run yet
118-
119-
// Purge board rules notifications
120-
$phpbb_notifications = $this->container->get('notification_manager');
121-
$phpbb_notifications->purge_notifications('phpbb.boardrules.notification.type.boardrules');
122-
return 'notifications';
123-
124-
break;
125-
126-
default:
127-
128-
// Run parent purge step method
129-
return parent::purge_step($old_state);
130-
131-
break;
103+
// Purge board rules notifications
104+
$phpbb_notifications = $this->container->get('notification_manager');
105+
$phpbb_notifications->purge_notifications('phpbb.boardrules.notification.type.boardrules');
106+
return 'notifications';
132107
}
108+
109+
// Run parent purge step method
110+
return parent::purge_step($old_state);
133111
}
134112
}

migrations/v10x/m10_notification_counter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class m10_notification_counter extends \phpbb\db\migration\migration
2222
* @static
2323
* @access public
2424
*/
25-
static public function depends_on()
25+
public static function depends_on()
2626
{
2727
return array('\phpbb\boardrules\migrations\v10x\m1_initial_schema');
2828
}

migrations/v10x/m11_notification_type_update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function effectively_installed()
3939
* @static
4040
* @access public
4141
*/
42-
static public function depends_on()
42+
public static function depends_on()
4343
{
4444
return array(
4545
'\phpbb\boardrules\migrations\v10x\m10_notification_counter',

migrations/v10x/m12_update_rule_message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class m12_update_rule_message extends \phpbb\db\migration\migration
2222
* @static
2323
* @access public
2424
*/
25-
static public function depends_on()
25+
public static function depends_on()
2626
{
2727
return array(
2828
'\phpbb\boardrules\migrations\v10x\m1_initial_schema',

migrations/v10x/m1_initial_schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class m1_initial_schema extends \phpbb\db\migration\migration
2222
* @static
2323
* @access public
2424
*/
25-
static public function depends_on()
25+
public static function depends_on()
2626
{
2727
return array('\phpbb\db\migration\data\v31x\v312');
2828
}

migrations/v10x/m2_initial_data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class m2_initial_data extends \phpbb\db\migration\migration
2222
* @static
2323
* @access public
2424
*/
25-
static public function depends_on()
25+
public static function depends_on()
2626
{
2727
return array('\phpbb\boardrules\migrations\v10x\m1_initial_schema');
2828
}

0 commit comments

Comments
 (0)