Total Complexity | 60 |
Total Lines | 226 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
Complex classes like permissions often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use permissions, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class permissions |
||
13 | { |
||
14 | /** @var \phpbb\auth\auth */ |
||
|
|||
15 | protected $auth; |
||
16 | |||
17 | /** @var \phpbb\config\db */ |
||
18 | protected $config; |
||
19 | |||
20 | /** @var \phpbb\user */ |
||
21 | protected $user; |
||
22 | |||
23 | /** |
||
24 | * Constructor |
||
25 | * |
||
26 | * @param \phpbb\auth\auth $auth Auth object |
||
27 | * @param \phpbb\config\db $config Config object |
||
28 | * @param \phpbb\user $user User object |
||
29 | */ |
||
30 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\db $config, \phpbb\user $user) |
||
31 | { |
||
32 | $this->auth = $auth; |
||
33 | $this->config = $config; |
||
34 | $this->user = $user; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param array $post_data |
||
39 | * @return bool |
||
40 | */ |
||
41 | public function display_attachments_notice(array $post_data) |
||
42 | { |
||
43 | return (!$this->auth->acl_get('f_download', $post_data['forum_id']) && $post_data['post_attachment']); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param array $post_data |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function permanent_delete_allowed(array $post_data) |
||
51 | { |
||
52 | return ($this->auth->acl_get('m_delete', $post_data['forum_id']) || |
||
53 | ($this->auth->acl_get('f_delete', $post_data['forum_id']) && $this->user->data['user_id'] == $post_data['poster_id'])); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param int $poster_id |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function user_is_poster($poster_id) |
||
61 | { |
||
62 | return ($poster_id == $this->user->data['user_id']); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param int $forum_id |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function can_report_post($forum_id) |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param array $topic_data |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function topic_has_unapproved_posts(array $topic_data) |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param array $topic_data |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function topic_is_reported(array $topic_data) |
||
88 | { |
||
89 | return ($topic_data['topic_reported'] && !$topic_data['topic_moved_id'] && $this->auth->acl_get('m_report', $topic_data['forum_id'])) ? true : false; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @param array $topic_data |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function topic_is_locked(array $topic_data) |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param array $post_data |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function post_is_unapproved(array $post_data) |
||
106 | { |
||
107 | return (($post_data['post_visibility'] == ITEM_UNAPPROVED || $post_data['post_visibility'] == ITEM_REAPPROVE) && $this->auth->acl_get('m_approve', $post_data['forum_id'])) ? true : false; |
||
2 ignored issues
–
show
|
|||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @param array $post_data |
||
112 | * @param array $topic_data |
||
113 | * @return bool |
||
114 | */ |
||
115 | protected function edit_allowed(array $post_data, array $topic_data) |
||
116 | { |
||
117 | return ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit', $post_data['forum_id']) || ( |
||
118 | !$this->cannot_edit($post_data) && |
||
119 | !$this->cannot_edit_time($post_data) && |
||
120 | !$this->cannot_edit_locked($post_data, $topic_data) |
||
121 | ))); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param array $topic_data |
||
126 | * @return bool |
||
127 | */ |
||
128 | protected function quote_allowed(array $topic_data) |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param array $post_data |
||
137 | * @param array $topic_data |
||
138 | * @return bool |
||
139 | */ |
||
140 | protected function post_is_quotable(array $post_data, array $topic_data) |
||
141 | { |
||
142 | return ($post_data['post_visibility'] == ITEM_APPROVED && $topic_data['topic_first_post_id'] != $post_data['post_id']); |
||
1 ignored issue
–
show
|
|||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @param array $post_data |
||
147 | * @param array $topic_data |
||
148 | * @return bool |
||
149 | */ |
||
150 | protected function delete_allowed(array $post_data, array $topic_data) |
||
151 | { |
||
152 | return ($this->user->data['is_registered'] && (($this->auth->acl_get('m_delete', $post_data['forum_id']) || ($this->auth->acl_get('m_softdelete', $post_data['forum_id']) && $post_data['post_visibility'] != ITEM_DELETED)) || ( |
||
1 ignored issue
–
show
|
|||
153 | !$this->cannot_delete($post_data) && |
||
154 | !$this->cannot_delete_lastpost($post_data, $topic_data) && |
||
155 | !$this->cannot_delete_time($post_data) && |
||
156 | !$this->cannot_delete_locked($post_data, $topic_data) |
||
157 | ))); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @param array $post_data |
||
162 | * @return bool |
||
163 | */ |
||
164 | protected function softdelete_allowed(array $post_data) |
||
165 | { |
||
166 | return ($this->auth->acl_get('m_softdelete', $post_data['forum_id']) || |
||
167 | ($this->auth->acl_get('f_softdelete', $post_data['forum_id']) && $this->user->data['user_id'] == $post_data['poster_id'])) && ($post_data['post_visibility'] != ITEM_DELETED); |
||
1 ignored issue
–
show
|
|||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @param array $post_data |
||
172 | * @return bool |
||
173 | */ |
||
174 | protected function cannot_edit(array $post_data) |
||
175 | { |
||
176 | return (!$this->auth->acl_get('f_edit', $post_data['forum_id']) || $this->user->data['user_id'] != $post_data['poster_id']); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @param array $post_data |
||
181 | * @return bool |
||
182 | */ |
||
183 | protected function cannot_edit_time(array $post_data) |
||
184 | { |
||
185 | return ($this->config['edit_time'] && $post_data['post_time'] <= time() - ($this->config['edit_time'] * 60)); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * @param array $post_data |
||
190 | * @param array $topic_data |
||
191 | * @return bool |
||
192 | */ |
||
193 | protected function cannot_edit_locked(array $post_data, array $topic_data) |
||
194 | { |
||
195 | return ($topic_data['topic_status'] == ITEM_LOCKED || $post_data['post_edit_locked']); |
||
1 ignored issue
–
show
|
|||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @param array $post_data |
||
200 | * @return bool |
||
201 | */ |
||
202 | protected function cannot_delete(array $post_data) |
||
203 | { |
||
204 | return $this->user->data['user_id'] != $post_data['poster_id'] || ( |
||
205 | !$this->auth->acl_get('f_delete', $post_data['forum_id']) && |
||
206 | (!$this->auth->acl_get('f_softdelete', $post_data['forum_id']) || $post_data['post_visibility'] == ITEM_DELETED) |
||
1 ignored issue
–
show
|
|||
207 | ); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @param array $post_data |
||
212 | * @param array $topic_data |
||
213 | * @return bool |
||
214 | */ |
||
215 | protected function cannot_delete_lastpost(array $post_data, array $topic_data) |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @param array $post_data |
||
222 | * @return bool |
||
223 | */ |
||
224 | protected function cannot_delete_time(array $post_data) |
||
225 | { |
||
226 | return $this->config['delete_time'] && $post_data['post_time'] <= time() - ($this->config['delete_time'] * 60); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * we do not want to allow removal of the last post if a moderator locked it! |
||
231 | * @param array $post_data |
||
232 | * @param array $topic_data |
||
233 | * @return bool |
||
234 | */ |
||
235 | protected function cannot_delete_locked(array $post_data, array $topic_data) |
||
238 | } |
||
239 | } |
||
240 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths