These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | * Auto Groups extension for the phpBB Forum Software package. |
||
5 | * |
||
6 | * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> |
||
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
||
8 | * |
||
9 | */ |
||
10 | |||
11 | namespace phpbb\autogroups; |
||
12 | |||
13 | /** |
||
14 | * This ext class is optional and can be omitted if left empty. |
||
15 | * However you can add special (un)installation commands in the |
||
16 | * methods enable_step(), disable_step() and purge_step(). As it is, |
||
17 | * these methods are defined in \phpbb\extension\base, which this |
||
18 | * class extends, but you can overwrite them to give special |
||
19 | * instructions for those cases. |
||
20 | */ |
||
21 | class ext extends \phpbb\extension\base |
||
22 | { |
||
23 | /** |
||
24 | * Check whether or not the extension can be enabled. |
||
25 | * The current phpBB version should meet or exceed |
||
26 | * the minimum version required by this extension: |
||
27 | * |
||
28 | * Requires phpBB 3.2.0 due to the revised notifications system |
||
29 | * and new group helper. |
||
30 | * |
||
31 | * @return bool |
||
32 | * @access public |
||
33 | */ |
||
34 | public function is_enableable() |
||
35 | { |
||
36 | return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>='); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Overwrite enable_step to enable Auto Groups notifications |
||
41 | * before any included migrations are installed. |
||
42 | * |
||
43 | * @param mixed $old_state State returned by previous call of this method |
||
44 | * @return mixed Returns false after last step, otherwise temporary state |
||
45 | * @access public |
||
46 | */ |
||
47 | public function enable_step($old_state) |
||
48 | { |
||
49 | switch ($old_state) |
||
50 | { |
||
51 | case '': // Empty means nothing has run yet |
||
0 ignored issues
–
show
|
|||
52 | |||
53 | // Enable Auto Groups notifications |
||
54 | return $this->notification_handler('enable', array( |
||
55 | 'phpbb.autogroups.notification.type.group_added', |
||
56 | 'phpbb.autogroups.notification.type.group_removed', |
||
57 | )); |
||
58 | |||
59 | break; |
||
60 | |||
61 | default: |
||
0 ignored issues
–
show
The default body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a default statement must start on the line immediately following the statement. switch ($expr) {
default:
doSomething(); //right
break;
}
switch ($expr) {
default:
doSomething(); //wrong
break;
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
62 | |||
63 | // Run parent enable step method |
||
64 | return parent::enable_step($old_state); |
||
65 | |||
66 | break; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Overwrite disable_step to disable Auto Groups notifications |
||
72 | * before the extension is disabled. |
||
73 | * |
||
74 | * @param mixed $old_state State returned by previous call of this method |
||
75 | * @return mixed Returns false after last step, otherwise temporary state |
||
76 | * @access public |
||
77 | */ |
||
78 | public function disable_step($old_state) |
||
79 | { |
||
80 | switch ($old_state) |
||
81 | { |
||
82 | case '': // Empty means nothing has run yet |
||
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
83 | |||
84 | // Disable Auto Groups notifications |
||
85 | return $this->notification_handler('disable', array( |
||
86 | 'phpbb.autogroups.notification.type.group_added', |
||
87 | 'phpbb.autogroups.notification.type.group_removed', |
||
88 | )); |
||
89 | |||
90 | break; |
||
91 | |||
92 | default: |
||
0 ignored issues
–
show
The default body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a default statement must start on the line immediately following the statement. switch ($expr) {
default:
doSomething(); //right
break;
}
switch ($expr) {
default:
doSomething(); //wrong
break;
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
93 | |||
94 | // Run parent disable step method |
||
95 | return parent::disable_step($old_state); |
||
96 | |||
97 | break; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Overwrite purge_step to purge Auto Groups notifications before |
||
103 | * any included and installed migrations are reverted. |
||
104 | * |
||
105 | * @param mixed $old_state State returned by previous call of this method |
||
106 | * @return mixed Returns false after last step, otherwise temporary state |
||
107 | * @access public |
||
108 | */ |
||
109 | public function purge_step($old_state) |
||
110 | { |
||
111 | switch ($old_state) |
||
112 | { |
||
113 | case '': // Empty means nothing has run yet |
||
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
114 | |||
115 | // Purge Auto Groups notifications |
||
116 | return $this->notification_handler('purge', array( |
||
117 | 'phpbb.autogroups.notification.type.group_added', |
||
118 | 'phpbb.autogroups.notification.type.group_removed', |
||
119 | )); |
||
120 | |||
121 | break; |
||
122 | |||
123 | default: |
||
0 ignored issues
–
show
The default body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a default statement must start on the line immediately following the statement. switch ($expr) {
default:
doSomething(); //right
break;
}
switch ($expr) {
default:
doSomething(); //wrong
break;
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
124 | |||
125 | // Run parent purge step method |
||
126 | return parent::purge_step($old_state); |
||
127 | |||
128 | break; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Notification handler to call notification enable/disable/purge steps |
||
134 | * |
||
135 | * @param string $step The step (enable, disable, purge) |
||
136 | * @param array $notification_types The notification type names |
||
137 | * @return string Return notifications as temporary state |
||
138 | * @access protected |
||
139 | */ |
||
140 | protected function notification_handler($step, $notification_types) |
||
141 | { |
||
142 | $phpbb_notifications = $this->container->get('notification_manager'); |
||
143 | |||
144 | foreach ($notification_types as $notification_type) |
||
145 | { |
||
146 | $phpbb_notifications->{$step . '_notifications'}($notification_type); |
||
147 | } |
||
148 | |||
149 | return 'notifications'; |
||
150 | } |
||
151 | } |
||
152 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.