Skip to content

Commit 9bdeaa2

Browse files
committed
Code inspection updates for PHP 7
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent bdca268 commit 9bdeaa2

23 files changed

Lines changed: 71 additions & 93 deletions

composer.json

Lines changed: 1 addition & 1 deletion
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",

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: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
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
*
@@ -46,88 +46,67 @@ public function is_enableable()
4646
* before any included migrations are installed.
4747
*
4848
* @param mixed $old_state State returned by previous call of this method
49-
* @return mixed Returns false after last step, otherwise temporary state
49+
* @return bool|string Returns false after last step, otherwise temporary state
5050
* @access public
5151
*/
5252
public function enable_step($old_state)
5353
{
54-
switch ($old_state)
54+
// if nothing has run yet
55+
if ($old_state === false)
5556
{
56-
case '': // Empty means nothing has run yet
57-
58-
// Enable board rules notifications
59-
$phpbb_notifications = $this->container->get('notification_manager');
60-
$phpbb_notifications->enable_notifications('phpbb.boardrules.notification.type.boardrules');
61-
return 'notifications';
62-
63-
break;
64-
65-
default:
66-
67-
// Run parent enable step method
68-
return parent::enable_step($old_state);
69-
70-
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';
7161
}
62+
63+
// Run parent enable step method
64+
return parent::enable_step($old_state);
7265
}
7366

7467
/**
7568
* Overwrite disable_step to disable board rules notifications
7669
* before the extension is disabled.
7770
*
7871
* @param mixed $old_state State returned by previous call of this method
79-
* @return mixed Returns false after last step, otherwise temporary state
72+
* @return bool|string Returns false after last step, otherwise temporary state
8073
* @access public
8174
*/
8275
public function disable_step($old_state)
8376
{
84-
switch ($old_state)
77+
// if nothing has run yet
78+
if ($old_state === false)
8579
{
86-
case '': // Empty means nothing has run yet
87-
88-
// Disable board rules notifications
89-
$phpbb_notifications = $this->container->get('notification_manager');
90-
$phpbb_notifications->disable_notifications('phpbb.boardrules.notification.type.boardrules');
91-
return 'notifications';
92-
93-
break;
94-
95-
default:
96-
97-
// Run parent disable step method
98-
return parent::disable_step($old_state);
99-
100-
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';
10184
}
85+
86+
// Run parent disable step method
87+
return parent::disable_step($old_state);
10288
}
10389

10490
/**
10591
* Overwrite purge_step to purge board rules notifications before
10692
* any included and installed migrations are reverted.
10793
*
10894
* @param mixed $old_state State returned by previous call of this method
109-
* @return mixed Returns false after last step, otherwise temporary state
95+
* @return bool|string Returns false after last step, otherwise temporary state
11096
* @access public
11197
*/
11298
public function purge_step($old_state)
11399
{
114-
switch ($old_state)
100+
// if nothing has run yet
101+
if ($old_state === false)
115102
{
116-
case '': // Empty means nothing has run yet
117-
118-
// Purge board rules notifications
119-
$phpbb_notifications = $this->container->get('notification_manager');
120-
$phpbb_notifications->purge_notifications('phpbb.boardrules.notification.type.boardrules');
121-
return 'notifications';
122-
123-
break;
124-
125-
default:
126-
127-
// Run parent purge step method
128-
return parent::purge_step($old_state);
129-
130-
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';
131107
}
108+
109+
// Run parent purge step method
110+
return parent::purge_step($old_state);
132111
}
133112
}

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)