main_controller::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 12
dl 0
loc 27
rs 9.8666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 *
4
 * PayPal Donation extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015-2024 Skouat
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace skouat\ppde\controller;
12
13
use phpbb\config\config;
14
use phpbb\controller\helper;
15
use phpbb\language\language;
16
use phpbb\request\request;
17
use phpbb\template\template;
18
use phpbb\user;
19
use phpbb\user_loader;
20
use Symfony\Component\DependencyInjection\ContainerInterface;
21
22
class main_controller
23
{
24
	public $ppde_auth;
25
	protected $config;
26
	protected $container;
27
	protected $helper;
28
	protected $language;
29
	protected $actions_currency;
30
	protected $request;
31
	protected $template;
32
	protected $user;
33
	protected $user_loader;
34
	protected $root_path;
35
	protected $php_ext;
36
37
	/**
38
	 * Constructor
39
	 *
40
	 * @param config                           $config           Config object
41
	 * @param ContainerInterface               $container        Service container interface
42
	 * @param helper                           $helper           Controller helpers object
43
	 * @param language                         $language         Language user object
44
	 * @param \skouat\ppde\helpers\auth_helper $ppde_auth     PPDE auth actions object
45
	 * @param \skouat\ppde\actions\currency    $actions_currency PPDE currency actions object
46
	 * @param request                          $request          Request object
47
	 * @param template                         $template         Template object
48
	 * @param user                             $user             User object
49
	 * @param user_loader                      $user_loader      User loader object
50
	 * @param string                           $root_path        phpBB root path
51
	 * @param string                           $php_ext          phpEx
52
	 *
53
	 * @access public
54
	 */
55
	public function __construct(
56
		config $config,
57
		ContainerInterface $container,
58
		helper $helper,
59
		language $language,
60
		\skouat\ppde\helpers\auth_helper $ppde_auth,
61
		\skouat\ppde\actions\currency $actions_currency,
62
		request $request,
63
		template $template,
64
		user $user,
65
		user_loader $user_loader,
66
		string $root_path,
67
		string $php_ext
68
	)
69
	{
70
		$this->config = $config;
71
		$this->container = $container;
72
		$this->helper = $helper;
73
		$this->language = $language;
74
		$this->ppde_auth = $ppde_auth;
75
		$this->actions_currency = $actions_currency;
76
		$this->request = $request;
77
		$this->template = $template;
78
		$this->user = $user;
79
		$this->user_loader = $user_loader;
80
		$this->root_path = $root_path;
81
		$this->php_ext = $php_ext;
82
	}
83
84
	public function handle()
85
	{
86
		// We stop the execution of the code because nothing needs to be returned to phpBB.
87
		garbage_collection();
88
		exit_handler();
89
	}
90
91
	/**
92
	 * @return bool
93
	 * @access private
94
	 */
95
	public function donorlist_is_enabled(): bool
96
	{
97
		return $this->use_ipn() && $this->config['ppde_ipn_donorlist_enable'];
98
	}
99
100
	/**
101
	 * Check if IPN is enabled based on config value
102
	 *
103
	 * @return bool
104
	 * @access public
105
	 */
106
	public function use_ipn(): bool
107
	{
108
		return !empty($this->config['ppde_enable']) && !empty($this->config['ppde_ipn_enable']) && $this->is_ipn_requirement_satisfied();
109
	}
110
111
	/**
112
	 * Check if IPN requirements are satisfied based on config value
113
	 *
114
	 * @return bool
115
	 * @access public
116
	 */
117
	public function is_ipn_requirement_satisfied(): bool
118
	{
119
		return !empty($this->config['ppde_curl_detected']) && !empty($this->config['ppde_tls_detected']);
120
	}
121
122
	/**
123
	 * Get PayPal URI
124
	 * Used in form and in IPN process
125
	 *
126
	 * @param bool $is_test_ipn
127
	 *
128
	 * @return string
129
	 * @access public
130
	 */
131
	public function get_paypal_uri($is_test_ipn = false): string
132
	{
133
		$remote_list = ipn_paypal::get_remote_uri();
134
135
		if ($is_test_ipn || $this->use_sandbox())
136
		{
137
			return $remote_list[$this->config['ppde_sandbox_remote']]['uri'];
138
		}
139
140
		return $remote_list[$this->config['ppde_default_remote']]['uri'];
141
	}
142
143
	/**
144
	 * Check if Sandbox is enabled based on config value
145
	 *
146
	 * @return bool
147
	 * @access public
148
	 */
149
	public function use_sandbox(): bool
150
	{
151
		return $this->use_ipn() && !empty($this->config['ppde_sandbox_enable']) && $this->is_sandbox_founder_enable();
152
	}
153
154
	/**
155
	 * Check if Sandbox can be used by founders based on config value
156
	 *
157
	 * @return bool
158
	 * @access public
159
	 */
160
	public function is_sandbox_founder_enable(): bool
161
	{
162
		return (!empty($this->config['ppde_sandbox_founder_enable']) && ((int) $this->user->data['user_type'] === USER_FOUNDER)) || empty($this->config['ppde_sandbox_founder_enable']);
163
	}
164
}
165