Completed
Push — master ( 7d29c5...8ac802 )
by Jakub
20s
created

ucp_controller   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 95
Duplicated Lines 5.26 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 5
loc 95
ccs 36
cts 39
cp 0.9231
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A set_page_url() 0 4 1
A get_page_title() 0 4 1
A main() 5 32 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ads\controller;
12
13
/**
14
 * Front controller
15
 */
16
class ucp_controller
17
{
18
	/** @var \phpbb\ads\ad\manager */
19
	protected $manager;
20
21
	/** @var \phpbb\ads\controller\helper */
22
	protected $helper;
23
24
	/** @var \phpbb\user */
25
	protected $user;
26
27
	/** @var \phpbb\language\language */
28
	protected $language;
29
30
	/** @var \phpbb\template\template */
31
	protected $template;
32
33
	/** @var \phpbb\config\config */
34
	protected $config;
35
36
	/** @var string Custom form action */
37
	protected $u_action;
38
39
	/**
40
	 * Constructor
41
	 *
42
	 * @param \phpbb\ads\ad\manager					$manager 	Advertisement manager object
43
	 * @param \phpbb\ads\controller\helper			$helper		Helper object
44
	 * @param \phpbb\user							$user		User object
45
	 * @param \phpbb\language\language				$language	Language object
46
	 * @param \phpbb\template\template				$template	Template object
47
	 * @param \phpbb\config\config					$config		Config object
48
	 */
49 5
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\ads\controller\helper $helper, \phpbb\user $user, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\config\config $config)
50
	{
51 5
		$this->manager = $manager;
52 5
		$this->helper = $helper;
53 5
		$this->user = $user;
54 5
		$this->language = $language;
55 5
		$this->template = $template;
56 5
		$this->config = $config;
57 5
	}
58
59
	/**
60
	 * @param	string	$u_action	Action URL
61
	 */
62 5
	public function set_page_url($u_action)
63
	{
64 5
		$this->u_action = $u_action;
65 5
	}
66
67
	/**
68
	 * @return	string	Module language string
69
	 */
70 1
	public function get_page_title()
71
	{
72 1
		return $this->language->lang('UCP_PHPBB_ADS_STATS');
73
	}
74
75
	/**
76
	 * Display UCP ads module
77
	 */
78 4
	public function main()
79
	{
80 4
		$this->language->add_lang('ucp', 'phpbb/ads');
81
82 4
		foreach ($this->manager->get_ads_by_owner($this->user->data['user_id']) as $ad)
83
		{
84 1
			$ad_enabled = (int) $ad['ad_enabled'];
85 1
			$ad_expired = $this->helper->is_expired($ad);
86
87 1 View Code Duplication
			if ($ad_expired && $ad_enabled)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88 1
			{
89
				$ad_enabled = 0;
90
				$this->manager->update_ad($ad['ad_id'], array('ad_enabled' => 0));
91
			}
92
93 1
			$this->template->assign_block_vars($ad_expired ? 'expired' : 'ads', array(
94 1
				'NAME'			=> $ad['ad_name'],
95 1
				'START_DATE'	=> $ad['ad_start_date'],
96 1
				'END_DATE'		=> $ad['ad_end_date'],
97 1
				'VIEWS'			=> $ad['ad_views'],
98 1
				'VIEWS_LIMIT'	=> $ad['ad_views_limit'],
99 1
				'CLICKS'		=> $ad['ad_clicks'],
100 1
				'CLICKS_LIMIT'	=> $ad['ad_clicks_limit'],
101 1
				'S_ENABLED'		=> $ad_enabled,
102 1
			));
103 4
		}
104
105 4
		$this->template->assign_vars(array(
106 4
			'S_VIEWS_ENABLED'	=> $this->config['phpbb_ads_enable_views'],
107 4
			'S_CLICKS_ENABLED'	=> $this->config['phpbb_ads_enable_clicks'],
108 4
		));
109 4
	}
110
}
111