filters   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 40
ccs 0
cts 19
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A archive_filter() 0 11 2
A getSubscribedEvents() 0 4 1
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2017 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 filters implements EventSubscriberInterface
15
{
16
	/** @var \blitze\sitemaker\services\date_range */
0 ignored issues
show
Bug introduced by
The type blitze\sitemaker\services\date_range 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...
17
	protected $date_range;
18
19
	/**
20
	 * Constructor
21
	 *
22
	 * @param \blitze\sitemaker\services\date_range		$date_range			Date Range Object
23
	 */
24
	public function __construct(\blitze\sitemaker\services\date_range $date_range)
25
	{
26
		$this->date_range = $date_range;
27
	}
28
29
	/**
30
	 * @return array
31
	 */
32
	public static function getSubscribedEvents()
33
	{
34
		return array(
35
			'blitze.content.view.filter' => 'archive_filter',
36
		);
37
	}
38
39
	/**
40
	 * @param \phpbb\event\data $event
41
	 * @return void
42
	 */
43
	public function archive_filter(\phpbb\event\data $event)
44
	{
45
		if (isset($event['filters']['archive']))
46
		{
47
			$month = array_combine(array('year', 'mon'), explode('-', current($event['filters']['archive'])));
48
			$range = $this->date_range->get_month($month);
49
50
			$sql_array = $event['sql_array'];
51
			$sql_array['WHERE'][] = "t.topic_time BETWEEN {$range['start']} AND {$range['stop']}";
52
53
			$event['sql_array'] = $sql_array;
54
		}
55
	}
56
}
57