Completed
Pull Request — develop (#31)
by Mario
02:32
created

ext::enable_step()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 *
4
 * PayPal Donation extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015 Skouat
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace skouat\ppde;
12
13
/**
14
 * Extension class for custom enable/disable/purge actions
15
 *
16
 * NOTE TO EXTENSION DEVELOPERS:
17
 * Normally it is not necessary to define any functions inside the ext class below.
18
 * The ext class may contain special (un)installation commands in the methods
19
 * enable_step(), disable_step() and purge_step(). As it is, these methods are defined
20
 * in phpbb_extension_base, which this class extends, but you can overwrite them to
21
 * give special instructions for those cases.
22
 */
23
class ext extends \phpbb\extension\base
24
{
25
	/**
26
	 * Check whether or not the extension can be enabled.
27
	 * The current phpBB version should meet or exceed
28
	 * the minimum version required by this extension:
29
	 *
30
	 * Requires phpBB 3.1.3 due to usage of container aware migrations.
31
	 *
32
	 * @return bool
33
	 * @access public
34
	 */
35
	public function is_enableable()
36
	{
37
		$config = $this->container->get('config');
38
39
		return phpbb_version_compare($config['version'], '3.1.3', '>=');
40
	}
41
42
	/**
43
	 * Overwrite enable_step to enable extension notifications before any included migrations are installed.
44
	 *
45
	 * @param mixed $old_state State returned by previous call of this method
46
	 *
47
	 * @return mixed Returns false after last step, otherwise temporary state
48
	 * @access public
49
	 */
50
	public function enable_step($old_state)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
	{
52
		switch ($old_state)
53
		{
54
			case '': // Empty means nothing has run yet
55
				// Enable notifications
56
				return $this->notification_handler('enable', array('skouat.ppde.notification.type.donation_received'));
57
58
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
59
60
			default:
61
				// Run parent enable step method
62
				return parent::enable_step($old_state);
63
64
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
65
		}
66
	}
67
68
	/**
69
	 * Overwrite disable_step to disable extension notifications before the extension is disabled.
70
	 *
71
	 * @param mixed $old_state State returned by previous call of this method
72
	 *
73
	 * @return mixed Returns false after last step, otherwise temporary state
74
	 * @access public
75
	 */
76
	public function disable_step($old_state)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
	{
78
		switch ($old_state)
79
		{
80
			case '': // Empty means nothing has run yet
81
				// Disable notifications
82
				return $this->notification_handler('enable', array('skouat.ppde.notification.type.donation_received'));
83
84
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
85
86
			default:
87
				// Run parent disable step method
88
				return parent::disable_step($old_state);
89
90
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
91
		}
92
	}
93
94
	/**
95
	 * Overwrite purge_step to purge extension notifications before any included and installed migrations are reverted.
96
	 *
97
	 * @param mixed $old_state State returned by previous call of this method
98
	 *
99
	 * @return mixed Returns false after last step, otherwise temporary state
100
	 * @access public
101
	 */
102
	public function purge_step($old_state)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
	{
104
		switch ($old_state)
105
		{
106
			case '': // Empty means nothing has run yet
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
107
108
				// Purge notifications
109
				return $this->notification_handler('enable', array('skouat.ppde.notification.type.donation_received'));
110
111
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
112
113
			default:
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
114
115
				// Run parent purge step method
116
				return parent::purge_step($old_state);
117
118
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
119
		}
120
	}
121
122
	/**
123
	 * Notification handler to call notification enable/disable/purge steps
124
	 *
125
	 * @author        VSEphpbb (Matt Friedman)
126
	 * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
127
	 * @license       GNU General Public License, version 2 (GPL-2.0)
128
	 *
129
	 * @param string $step               The step (enable, disable, purge)
130
	 * @param array  $notification_types The notification type names
131
	 *
132
	 * @return string Return notifications as temporary state
133
	 * @access        protected
134
	 */
135
	protected function notification_handler($step, $notification_types)
136
	{
137
		/** @type \phpbb\notification\manager $phpbb_notifications */
138
		$phpbb_notifications = $this->container->get('notification_manager');
139
140
		foreach ($notification_types as $notification_type)
141
		{
142
			call_user_func(array($phpbb_notifications, $step . '_notifications'), $notification_type);
143
		}
144
145
		return 'notifications';
146
	}
147
}
148