v310_m1_remove_data::abbc3_bbcodes()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 56
nc 1
nop 0
dl 0
loc 65
rs 8.9599
c 2
b 1
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
*
4
* Advanced BBCode Box
5
*
6
* @copyright (c) 2013 Matt Friedman
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace vse\abbc3\migrations;
12
13
/**
14
* This migration removes old data from 3.0
15
* installations of Advanced BBCode Box 3 MOD.
16
*/
17
class v310_m1_remove_data extends \phpbb\db\migration\container_aware_migration
0 ignored issues
show
Bug introduced by
The type phpbb\db\migration\container_aware_migration 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...
18
{
19
	/**
20
	 * Run migration if ABBC3_VERSION config exists
21
	 *
22
	 * @return bool
23
	 */
24
	public function effectively_installed()
25
	{
26
		return !isset($this->config['ABBC3_VERSION']);
27
	}
28
29
	/**
30
	 * This dependency is needed mostly for testing, to ensure
31
	 * phpBB migrations are installed before ABBC3.
32
	 *
33
	 * @return array An array of migration class names
34
	 */
35
	public static function depends_on()
36
	{
37
		return array('\phpbb\db\migration\data\v310\beta4');
38
	}
39
40
	/**
41
	 * {@inheritdoc}
42
	 */
43
	public function update_data()
44
	{
45
		// use module tool explicitly since module.exists does not work in 'if'
46
		$module_tool = $this->container->get('migrator.tool.module');
47
48
		return array(
49
			array('if', array(
50
				$module_tool->exists('acp', false, 'ACP_ABBC3_BBCODES', true),
51
				array('module.remove', array('acp', false, 'ACP_ABBC3_BBCODES')),
52
			)),
53
			array('if', array(
54
				$module_tool->exists('acp', false, 'ACP_ABBC3_SETTINGS', true),
55
				array('module.remove', array('acp', false, 'ACP_ABBC3_SETTINGS')),
56
			)),
57
			array('if', array(
58
				$module_tool->exists('acp', false, 'ACP_ABBCODES', true),
59
				array('module.remove', array('acp', false, 'ACP_ABBCODES')),
60
			)),
61
62
			// Custom functions
63
			array('custom', array(array($this, 'remove_abbc3_configs'))),
64
			array('custom', array(array($this, 'remove_abbc3_bbcodes'))),
65
		);
66
	}
67
68
	/**
69
	 * Remove config data from ABBC3 MOD
70
	 */
71
	public function remove_abbc3_configs()
72
	{
73
		$sql = 'DELETE FROM ' . $this->table_prefix . 'config
74
			WHERE config_name ' . $this->db->sql_like_expression('ABBC3_' . $this->db->get_any_char());
75
		$this->db->sql_query($sql);
76
	}
77
78
	/**
79
	 * Remove BBCodes from ABBC3 MOD
80
	 */
81
	public function remove_abbc3_bbcodes()
82
	{
83
		$abbc3_bbcode_deprecated = $this->abbc3_bbcodes();
84
85
		// Add all breaks and divisions to the array
86
		$sql = 'SELECT bbcode_tag
87
			FROM ' . $this->table_prefix . 'bbcodes
88
			WHERE bbcode_tag ' . $this->db->sql_like_expression('break' . $this->db->get_any_char()) . '
89
			OR bbcode_tag ' . $this->db->sql_like_expression('division' . $this->db->get_any_char());
90
91
		$result = $this->db->sql_query($sql);
92
		while ($row = $this->db->sql_fetchrow($result))
93
		{
94
			$abbc3_bbcode_deprecated[] = $row['bbcode_tag'];
95
		}
96
		$this->db->sql_freeresult($result);
97
98
		// Delete all the unwanted BBCodes
99
		$sql = 'DELETE FROM ' . $this->table_prefix . 'bbcodes
100
			WHERE ' . $this->db->sql_in_set('bbcode_tag', $abbc3_bbcode_deprecated) . '
101
			OR bbcode_id < 0';
102
		$this->db->sql_query($sql);
103
	}
104
105
	/**
106
	 * Array of ABBC3 MOD BBCodes to remove
107
	 *
108
	 * @return array
109
	 */
110
	public function abbc3_bbcodes()
111
	{
112
		return array(
113
			// These exist in core
114
			'b',
115
			'code',
116
			'color',
117
			'email',
118
			'flash',
119
			'i',
120
			'img=',
121
			'listb',
122
			'listitem',
123
			'listo',
124
			'quote',
125
			'size',
126
			'u',
127
			'url',
128
			'url=',
129
130
			// These were not really BBCodes
131
			'copy',
132
			'cut',
133
			'grad',
134
			'paste',
135
			'plain',
136
			'imgshack',
137
138
			// These are deprecated
139
			'click',
140
			'ed2k',
141
			'flv',
142
			'quicktime',
143
			'ram',
144
			'rapidshare',
145
			'stream',
146
			'testlink',
147
			'video',
148
			'wave=',
149
			'web',
150
			'scrippet',
151
			'search',
152
			'thumbnail',
153
			'hr',
154
			'tab=',
155
			'tabs',
156
			'table=',
157
			'anchor=',
158
			'upload',
159
			'html',
160
			'collegehumor',
161
			'dm',
162
			'gamespot',
163
			'ignvideo',
164
			'liveleak',
165
			'veoh',
166
167
			// These are being replaced by new BBCodes
168
			'align=justify',	// replaced by align=
169
			'align=left',		// replaced by align=
170
			'align=right',		// replaced by align=
171
			'dir=rtl',			// replaced by dir=
172
			'marq=down',		// replaced by marq=
173
			'marq=left',		// replaced by marq=
174
			'marq=right',		// replaced by marq=
175
		);
176
	}
177
}
178