Passed
Push — develop ( 49e842...20d485 )
by Daniel
03:55
created

mcp_post   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A __construct() 0 7 1
B modify_post_data() 0 22 4
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2018 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\event;
11
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
14
class mcp_post implements EventSubscriberInterface
15
{
16
	/** @var \phpbb\db\driver\driver_interface */
17
	protected $db;
18
19
	/* @var \blitze\content\services\types */
20
	protected $content_types;
21
22
	/* @var \blitze\content\services\fields */
23
	protected $fields;
24
25
	/** @var string */
26
	protected $phpbb_root_path;
27
28
	/** @var string */
29
	protected $php_ext;
30
31
	/** @var string|false */
32
	private $type;
0 ignored issues
show
introduced by
The private property $type is not used, and could be removed.
Loading history...
33
34
	/**
35
	 * Constructor
36
	 *
37
	 * @param \phpbb\db\driver\driver_interface		$db					Database object
38
	 * @param \blitze\content\services\types		$content_types		Content types object
39
	 * @param \blitze\content\services\fields		$fields				Content fields object
40
	 * @param string								$phpbb_root_path	Path to the phpbb includes directory.
41
	 * @param string								$php_ext			php file extension
42
	*/
43
	public function __construct(\phpbb\db\driver\driver_interface $db, \blitze\content\services\types $content_types, \blitze\content\services\fields $fields, $phpbb_root_path, $php_ext)
44
	{
45
		$this->db = $db;
46
		$this->content_types = $content_types;
47
		$this->fields = $fields;
48
		$this->phpbb_root_path = $phpbb_root_path;
49
		$this->php_ext = $php_ext;
50
	}
51
52
	/**
53
	 * @return array
54
	 */
55
	public static function getSubscribedEvents()
56
	{
57
		return array(
58
			'core.mcp_post_template_data'	=> 'modify_post_data',
59
		);
60
	}
61
62
	/**
63
	 * @param \phpbb\event\data $event
64
	 * @return void
65
	 */
66
	public function modify_post_data(\phpbb\event\data $event)
67
	{
68
		if (
69
			($type = $this->content_types->get_forum_type($event['post_info']['forum_id'])) !== false
70
			&& $event['post_info']['post_id'] === $event['post_info']['topic_first_post_id']
71
		)
72
		{
73
			$entity = $this->content_types->get_type($type);
74
75
			$this->fields->prepare_to_show($entity, array($event['post_info']['topic_id']), $entity->get_summary_fields(), $entity->get_summary_tpl(), 'summary');
1 ignored issue
show
Bug introduced by
It seems like $entity can also be of type false; however, parameter $entity of blitze\content\services\fields::prepare_to_show() does only seem to accept blitze\content\model\entity\type, maybe add an additional type check? ( Ignorable by Annotation )

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

75
			$this->fields->prepare_to_show(/** @scrutinizer ignore-type */ $entity, array($event['post_info']['topic_id']), $entity->get_summary_fields(), $entity->get_summary_tpl(), 'summary');
Loading history...
76
			$users_cache = $attachments = $topic_tracking_info = $update_count = array();
77
78
			$post_data = $event['post_info'];
79
			$topic_data = $event['post_info'];
80
			$users_cache[$post_data['poster_id']] = array();
81
82
			$tpl_data = $this->fields->get_summary_template_data($type, $topic_data, $post_data, $users_cache, $attachments, $topic_tracking_info, $update_count);
0 ignored issues
show
Bug introduced by
It seems like $topic_data can also be of type null; however, parameter $topic_data of blitze\content\services\...summary_template_data() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

82
			$tpl_data = $this->fields->get_summary_template_data($type, /** @scrutinizer ignore-type */ $topic_data, $post_data, $users_cache, $attachments, $topic_tracking_info, $update_count);
Loading history...
Bug introduced by
It seems like $post_data can also be of type null; however, parameter $post_data of blitze\content\services\...summary_template_data() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

82
			$tpl_data = $this->fields->get_summary_template_data($type, $topic_data, /** @scrutinizer ignore-type */ $post_data, $users_cache, $attachments, $topic_tracking_info, $update_count);
Loading history...
83
			$content = $this->fields->build_content($tpl_data);
84
85
			$mcp_post_template_data = $event['mcp_post_template_data'];
86
			$mcp_post_template_data['POST_PREVIEW'] = isset($content['CUSTOM_DISPLAY']) ? $content['CUSTOM_DISPLAY'] : join('', $content['FIELDS']['all']);
87
			$event['mcp_post_template_data'] = $mcp_post_template_data;
88
		}
89
	}
90
}
91