Conditions | 6 |
Paths | 24 |
Total Lines | 78 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
69 | public function create_bbcodes() |
||
70 | { |
||
71 | if (!class_exists('acp_bbcodes')) |
||
72 | { |
||
73 | include($this->phpbb_root_path . 'includes/acp/acp_bbcodes.' . $this->php_ext); |
||
74 | } |
||
75 | |||
76 | $bbcodes_ary = array( |
||
77 | array( |
||
78 | 'match' => '[tag={IDENTIFIER}]{TEXT}[/tag]', |
||
79 | 'template' => "<!-- begin field -->\n" . |
||
80 | "<h4>{IDENTIFIER}</h4><br />\n" . |
||
81 | "<div data-field=\"{IDENTIFIER}\">{TEXT}</div><br />\n" . |
||
82 | "<!-- end field -->\n", |
||
83 | ), |
||
84 | array( |
||
85 | 'match' => '[page={SIMPLETEXT}]{TEXT}[/page]', |
||
86 | 'template' => "<!-- begin page -->\n" . |
||
87 | "<i>{SIMPLETEXT}</i>\n" . |
||
88 | "<div data-page=\"{SIMPLETEXT}\">{TEXT}</div><br />\n" . |
||
89 | "<!-- end page -->\n", |
||
90 | ), |
||
91 | ); |
||
92 | |||
93 | $sql = 'SELECT bbcode_id, bbcode_tag |
||
94 | FROM ' . BBCODES_TABLE . ' |
||
95 | ORDER BY bbcode_id ASC'; |
||
96 | $result = $this->db->sql_query($sql); |
||
97 | |||
98 | $max_bbcode_id = NUM_CORE_BBCODES; |
||
99 | $current_bbcodes = array(); |
||
100 | |||
101 | while ($row = $this->db->sql_fetchrow($result)) |
||
102 | { |
||
103 | $max_bbcode_id = (int) $row['bbcode_id']; |
||
104 | $current_bbcodes[$row['bbcode_tag']] = $row['bbcode_id']; |
||
105 | } |
||
106 | $this->db->sql_freeresult($result); |
||
107 | |||
108 | // Make sure max_bbcode_id is not less than the core bbcode ids... |
||
109 | if ($max_bbcode_id < NUM_CORE_BBCODES) |
||
110 | { |
||
111 | $max_bbcode_id = NUM_CORE_BBCODES; |
||
112 | } |
||
113 | |||
114 | $bbcode_manager = new \acp_bbcodes(); |
||
115 | |||
116 | foreach ($bbcodes_ary as $bbcode) |
||
117 | { |
||
118 | $data = $bbcode_manager->build_regexp($bbcode['match'], $bbcode['template']); |
||
119 | |||
120 | $sql_ary = array( |
||
121 | 'bbcode_tag' => $data['bbcode_tag'], |
||
122 | 'bbcode_match' => $bbcode['match'], |
||
123 | 'bbcode_tpl' => $bbcode['template'], |
||
124 | 'display_on_posting' => false, |
||
125 | 'bbcode_helpline' => '', |
||
126 | 'first_pass_match' => $data['first_pass_match'], |
||
127 | 'first_pass_replace' => $data['first_pass_replace'], |
||
128 | 'second_pass_match' => $data['second_pass_match'], |
||
129 | 'second_pass_replace' => $data['second_pass_replace'] |
||
130 | ); |
||
131 | |||
132 | // Does this bbcode already exist? |
||
133 | if (isset($current_bbcodes[$sql_ary['bbcode_tag']])) |
||
134 | { |
||
135 | $this->db->sql_query('UPDATE ' . BBCODES_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE bbcode_id = ' . (int) $current_bbcodes[$sql_ary['bbcode_tag']]); |
||
136 | } |
||
137 | else |
||
138 | { |
||
139 | $sql_ary['bbcode_id'] = ++$max_bbcode_id; |
||
140 | |||
141 | $this->db->sql_query('INSERT INTO ' . BBCODES_TABLE . $this->db->sql_build_array('INSERT', $sql_ary)); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $this->container->get('cache.driver')->destroy('sql', BBCODES_TABLE); |
||
146 | } |
||
147 | } |
||
148 |