Passed
Push — develop ( 73b4e9...8d0058 )
by Daniel
05:19
created

permissions::post_is_quotable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 2
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2016 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services;
11
12
class permissions
13
{
14
	/** @var \phpbb\auth\auth */
0 ignored issues
show
Bug introduced by
The type phpbb\auth\auth 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...
15
	protected $auth;
16
17
	/** @var \phpbb\config\db */
0 ignored issues
show
Bug introduced by
The type phpbb\config\db 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
	protected $config;
19
20
	/** @var \phpbb\user */
0 ignored issues
show
Bug introduced by
The type phpbb\user 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...
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)
70
	{
71
		return ($this->auth->acl_get('f_report', $forum_id));
72
	}
73
74
	/**
75
	 * @param array $topic_data
76
	 * @return bool
77
	 */
78
	public function topic_has_unapproved_posts(array $topic_data)
79
	{
80
		return ($topic_data['topic_visibility'] == ITEM_APPROVED && $topic_data['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $topic_data['forum_id']));
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\ITEM_APPROVED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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)
97
	{
98
		return ($topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED) ? false : true;
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\ITEM_UNLOCKED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
Bug introduced by
The constant blitze\content\services\ITEM_UNAPPROVED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant blitze\content\services\ITEM_REAPPROVE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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)
129
	{
130
		return $this->auth->acl_get('m_edit', $topic_data['forum_id']) || ($topic_data['topic_status'] != ITEM_LOCKED &&
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\ITEM_LOCKED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
131
			($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('f_reply', $topic_data['forum_id']))
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
Bug introduced by
The constant blitze\content\services\ITEM_APPROVED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
Bug introduced by
The constant blitze\content\services\ITEM_DELETED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
Bug introduced by
The constant blitze\content\services\ITEM_DELETED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
Bug introduced by
The constant blitze\content\services\ITEM_LOCKED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
Bug introduced by
The constant blitze\content\services\ITEM_DELETED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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)
216
	{
217
		return $topic_data['topic_last_post_id'] != $post_data['post_id'];
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)
236
	{
237
		return $topic_data['topic_status'] == ITEM_LOCKED || $post_data['post_edit_locked'];
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\ITEM_LOCKED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
238
	}
239
}
240