tracker   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 71
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
A can_track_anonymous() 0 3 3
A __construct() 0 4 1
A can_track_by_lastread() 0 3 3
A get_tracking_info() 0 13 3
A build_tracking_info() 0 9 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\forum;
11
12
class tracker
13
{
14
	/** @var \phpbb\config\config */
15
	protected $config;
16
17
	/** @var \phpbb\user */
18
	protected $user;
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\config\config		$config			Config object
24
	 * @param \phpbb\user				$user			User object
25
	 */
26 6
	public function __construct(\phpbb\config\config $config, \phpbb\user $user)
27
	{
28 6
		$this->config = $config;
29 6
		$this->user = $user;
30 6
	}
31
32
	/**
33
	 * @param array $forums
34
	 * @param array $topics
35
	 * @return array
36
	 */
37 6
	public function get_tracking_info(array $forums, array &$topics)
38
	{
39 6
		$info = array();
40 6
		if ($this->can_track_by_lastread())
41 6
		{
42 5
			$info = $this->build_tracking_info('get_topic_tracking', $forums, $topics);
43 5
		}
44 1
		else if ($this->can_track_anonymous())
45 1
		{
46 1
			$info = $this->build_tracking_info('get_complete_topic_tracking', $forums, $topics);
47 1
		}
48
49 6
		return $info;
50
	}
51
52
	/**
53
	 * @param string $function
54
	 * @param array $forums
55
	 * @param array $topics
56
	 * @return array
57
	 */
58 6
	protected function build_tracking_info($function, array $forums, array &$topics)
59
	{
60 6
		$tracking_info = array();
61 6
		foreach ($forums as $fid => $forum)
62
		{
63 6
			$tracking_info[$fid] = call_user_func_array($function, array($fid, $forum['topic_list'], &$topics, array($fid => $forum['mark_time'])));
64 6
		}
65
66 6
		return $tracking_info;
67
	}
68
69
	/**
70
	 * @return bool
71
	 */
72 6
	protected function can_track_by_lastread()
73
	{
74 6
		return ($this->config['load_db_lastread'] && $this->user->data['is_registered']) ? true : false;
75
	}
76
77
	/**
78
	 * @return bool
79
	 */
80 1
	protected function can_track_anonymous()
81
	{
82 1
		return ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) ? true : false;
83
	}
84
}
85