ext   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 28
dl 0
loc 134
rs 10
c 5
b 1
f 0
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A purge_step() 0 14 2
A disable_step() 0 14 2
A check_phpbb_version() 0 3 1
A notification_handler() 0 10 2
A check_php_version() 0 3 1
A is_enableable() 0 12 4
A enable_step() 0 14 2
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
0 ignored issues
show
Bug introduced by
The type phpbb\extension\base was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
{
23
	/**
24
	 * Check whether the extension can be enabled.
25
	 * The current phpBB version should meet or exceed
26
	 * the minimum version required by this extension:
27
	 *
28
	 * @return bool|array
29
	 * @access public
30
	 */
31
	public function is_enableable()
32
	{
33
		$enableable = $this->check_phpbb_version() && $this->check_php_version();
34
35
		if (!$enableable && phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>='))
0 ignored issues
show
Bug introduced by
The constant phpbb\autogroups\PHPBB_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function phpbb_version_compare was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
		if (!$enableable && /** @scrutinizer ignore-call */ phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>='))
Loading history...
36
		{
37
			$language = $this->container->get('language');
38
			$language->add_lang('autogroups_install', 'phpbb/autogroups');
39
			return $language->lang('AUTOGROUPS_NOT_ENABLEABLE');
40
		}
41
42
		return $enableable;
43
	}
44
45
	/**
46
	 * Require phpBB 3.2.0 due to the revised notifications system and new group helper.
47
	 *
48
	 * @return bool
49
	 */
50
	protected function check_phpbb_version()
51
	{
52
		return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=');
0 ignored issues
show
Bug introduced by
The constant phpbb\autogroups\PHPBB_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function phpbb_version_compare was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
		return /** @scrutinizer ignore-call */ phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=');
Loading history...
53
	}
54
55
	/**
56
	 * Requires PHP 5.5 due to array_column().
57
	 *
58
	 * @return bool
59
	 */
60
	protected function check_php_version()
61
	{
62
		return PHP_VERSION_ID >= 50500;
63
	}
64
65
	/**
66
	 * Overwrite enable_step to enable Auto Groups notifications
67
	 * before any included migrations are installed.
68
	 *
69
	 * @param mixed $old_state State returned by previous call of this method
70
	 * @return mixed Returns false after last step, otherwise temporary state
71
	 * @access public
72
	 */
73
	public function enable_step($old_state)
74
	{
75
		// if nothing has run yet
76
		if ($old_state === false)
77
		{
78
			// Enable Auto Groups notifications
79
			return $this->notification_handler('enable', array(
80
				'phpbb.autogroups.notification.type.group_added',
81
				'phpbb.autogroups.notification.type.group_removed',
82
			));
83
		}
84
85
		// Run parent enable step method
86
		return parent::enable_step($old_state);
87
	}
88
89
	/**
90
	 * Overwrite disable_step to disable Auto Groups notifications
91
	 * before the extension is disabled.
92
	 *
93
	 * @param mixed $old_state State returned by previous call of this method
94
	 * @return mixed Returns false after last step, otherwise temporary state
95
	 * @access public
96
	 */
97
	public function disable_step($old_state)
98
	{
99
		// if nothing has run yet
100
		if ($old_state === false)
101
		{
102
			// Disable Auto Groups notifications
103
			return $this->notification_handler('disable', array(
104
				'phpbb.autogroups.notification.type.group_added',
105
				'phpbb.autogroups.notification.type.group_removed',
106
			));
107
		}
108
109
		// Run parent disable step method
110
		return parent::disable_step($old_state);
111
	}
112
113
	/**
114
	 * Overwrite purge_step to purge Auto Groups notifications before
115
	 * any included and installed migrations are reverted.
116
	 *
117
	 * @param mixed $old_state State returned by previous call of this method
118
	 * @return mixed Returns false after last step, otherwise temporary state
119
	 * @access public
120
	 */
121
	public function purge_step($old_state)
122
	{
123
		// if nothing has run yet
124
		if ($old_state === false)
125
		{
126
			// Purge Auto Groups notifications
127
			return $this->notification_handler('purge', array(
128
				'phpbb.autogroups.notification.type.group_added',
129
				'phpbb.autogroups.notification.type.group_removed',
130
			));
131
		}
132
133
		// Run parent purge step method
134
		return parent::purge_step($old_state);
135
	}
136
137
	/**
138
	 * Notification handler to call notification enable/disable/purge steps
139
	 *
140
	 * @param string $step               The step (enable, disable, purge)
141
	 * @param array  $notification_types The notification type names
142
	 * @return string Return notifications as temporary state
143
	 * @access protected
144
	 */
145
	protected function notification_handler($step, $notification_types)
146
	{
147
		$phpbb_notifications = $this->container->get('notification_manager');
148
149
		foreach ($notification_types as $notification_type)
150
		{
151
			$phpbb_notifications->{$step . '_notifications'}($notification_type);
152
		}
153
154
		return 'notifications';
155
	}
156
}
157