Completed
Pull Request — development (#3620)
by Emanuele
07:38 queued 07:38
created

Display::hooks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 19
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * Integration system for attachments into Diplay controller
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * This file contains code covered by:
11
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
12
 *
13
 * @version 2.0 dev
14
 *
15
 */
16
17
namespace ElkArte\Modules\Attachments;
18
19
use ElkArte\AttachmentsDisplay;
20
use ElkArte\EventManager;
21
use ElkArte\Modules\AbstractModule;
22
23
/**
24
 * Class \ElkArte\Modules\Attachments\Display
25
 */
26
class Display extends AbstractModule
27
{
28
	/** @var int The mode of attachments (disabled/enabled/show only). */
29
	protected static $attach_level = 0;
30
31
	/** @var The good old attachments array */
0 ignored issues
show
Bug introduced by
The type ElkArte\Modules\Attachments\The 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...
32
	protected static $attachments = null;
33
34
	/** @var bool If unapproved posts/attachments should be shown */
35
	protected static $includeUnapproved = false;
36
37
	/**
38
	 * {@inheritdoc }
39
	 */
40
	public static function hooks(EventManager $eventsManager)
41
	{
42
		global $modSettings;
43
44
		if (!empty($modSettings['attachmentEnable']))
45
		{
46
			require_once(SUBSDIR . '/Attachments.subs.php');
47
48
			self::$attach_level = (int) $modSettings['attachmentEnable'];
49
			self::$includeUnapproved = !$modSettings['postmod_active'] || allowedTo('approve_posts');
50
51
			add_integration_function('integrate_display_message_list', '\\ElkArte\\Modules\\Attachments\\Display::integrate_display_message_list', '', false);
52
			add_integration_function('integrate_prepare_display_context', '\\ElkArte\\Modules\\Attachments\\Display::integrate_prepare_display_context', '', false);
53
// 			return array(
54
// 				array('prepare_context', array('\\ElkArte\\Modules\\Attachments\\Display', 'prepare_context'), array('post_errors')),
55
// 			);
56
		}
57
58
		return array();
59
	}
60
61
	/**
62
	 * Loads up all the attachments
63
	 */
64
	public static function integrate_display_message_list(&$messages, &$posters)
65
	{
66
		self::$attachments = new AttachmentsDisplay($messages, $posters, self::$includeUnapproved);
0 ignored issues
show
Documentation Bug introduced by
It seems like new ElkArte\AttachmentsD...elf::includeUnapproved) of type ElkArte\AttachmentsDisplay is incompatible with the declared type ElkArte\Modules\Attachments\The of property $attachments.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
67
	}
68
69
	/**
70
	 * Shows the attachments for the current message
71
	 */
72
	public static function integrate_prepare_display_context(&$output, &$this_message, $counter)
0 ignored issues
show
Unused Code introduced by
The parameter $counter is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
	public static function integrate_prepare_display_context(&$output, &$this_message, /** @scrutinizer ignore-unused */ $counter)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
	{
74
		$output['attachment'] = self::$attachments->loadAttachmentContext($this_message['id_msg']);
75
	}
76
}
77