Passed
Branch develop-3.3.x-donors_module (d1eba4)
by Mario
03:56
created

paypal_features_controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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

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-2020 Skouat
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace skouat\ppde\controller\admin;
12
13
use phpbb\config\config;
14
use phpbb\language\language;
15
use phpbb\log\log;
16
use phpbb\request\request;
17
use phpbb\template\template;
18
use phpbb\user;
19
use skouat\ppde\controller\ipn_paypal;
20
use skouat\ppde\controller\main_controller;
21
22
/**
23
 * @property config   config             Config object
24
 * @property string   id_prefix_name     Prefix name for identifier in the URL
25
 * @property string   lang_key_prefix    Prefix for the messages thrown by exceptions
26
 * @property language language           Language object
27
 * @property log      log                The phpBB log system
28
 * @property string   module_name        Name of the module currently used
29
 * @property request  request            Request object
30
 * @property bool     submit             State of submit $_POST variable
31
 * @property template template           Template object
32
 * @property string   u_action           Action URL
33
 * @property user     user               User object
34
 */
35
class paypal_features_controller extends admin_main
36
{
37
	protected $ppde_controller_main;
38
	protected $ppde_ipn_paypal;
39
40
	/**
41
	 * Constructor
42
	 *
43
	 * @param config          $config               Config object
44
	 * @param language        $language             Language object
45
	 * @param log             $log                  The phpBB log system
46
	 * @param main_controller $ppde_controller_main Main controller object
47
	 * @param ipn_paypal      $ppde_ipn_paypal      IPN PayPal object
48
	 * @param request         $request              Request object
49
	 * @param template        $template             Template object
50
	 * @param user            $user                 User object
51
	 *
52
	 * @access public
53
	 */
54
	public function __construct(
55
		config $config,
56
		language $language,
57
		log $log,
58
		main_controller $ppde_controller_main,
59
		ipn_paypal $ppde_ipn_paypal,
60
		request $request,
61
		template $template,
62
		user $user
63
	)
64
	{
65
		$this->config = $config;
66
		$this->language = $language;
67
		$this->log = $log;
68
		$this->ppde_controller_main = $ppde_controller_main;
69
		$this->ppde_ipn_paypal = $ppde_ipn_paypal;
70
		$this->request = $request;
71
		$this->template = $template;
72
		$this->user = $user;
73
		parent::__construct(
74
			'paypal_features',
75
			'PPDE_PAYPAL_FEATURES',
76
			''
77
		);
78
	}
79
80
	/**
81
	 * Display the settings a user can configure for this extension
82
	 *
83
	 * @return void
84
	 * @access public
85
	 */
86
	public function display()
87
	{
88
		if ($this->config['ppde_first_start'])
89
		{
90
			$this->ppde_ipn_paypal->set_curl_info();
91
			$this->ppde_ipn_paypal->set_remote_detected();
92
			$this->ppde_ipn_paypal->check_tls();
93
			$this->config->set('ppde_first_start', '0');
94
		}
95
96
		// Define the name of the form for use as a form key
97
		add_form_key('ppde_paypal_features');
98
99
		// Create an array to collect errors that will be output to the user
100
		$errors = [];
101
102
		$this->submit_settings();
103
104
		// Set output vars for display in the template
105
		$this->s_error_assign_template_vars($errors);
106
		$this->u_action_assign_template_vars();
107
		$this->build_remote_uri_select_menu($this->config['ppde_sandbox_remote'], 'sandbox');
108
		$this->template->assign_vars([
109
			// PayPal IPN vars
110
			'PPDE_IPN_AG_MIN_BEFORE_GROUP'   => $this->check_config($this->config['ppde_ipn_min_before_group'], 'integer', 0),
111
			'S_PPDE_IPN_AG_ENABLE'           => $this->check_config($this->config['ppde_ipn_autogroup_enable']),
112
			'S_PPDE_IPN_AG_GROUP_AS_DEFAULT' => $this->check_config($this->config['ppde_ipn_group_as_default']),
113
			'S_PPDE_IPN_DL_ALLOW_GUEST'      => $this->check_config($this->config['ppde_ipn_dl_allow_guest'], 'boolean', false),
114
			'S_PPDE_IPN_DL_ENABLE'           => $this->check_config($this->config['ppde_ipn_donorlist_enable']),
115
			'S_PPDE_IPN_ENABLE'              => $this->check_config($this->config['ppde_ipn_enable']),
116
			'S_PPDE_IPN_GROUP_OPTIONS'       => group_select_options($this->config['ppde_ipn_group_id']),
0 ignored issues
show
Bug introduced by
$this->config['ppde_ipn_group_id'] of type string is incompatible with the type integer expected by parameter $group_id of group_select_options(). ( Ignorable by Annotation )

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

116
			'S_PPDE_IPN_GROUP_OPTIONS'       => group_select_options(/** @scrutinizer ignore-type */ $this->config['ppde_ipn_group_id']),
Loading history...
117
			'S_PPDE_IPN_LOGGING'             => $this->check_config($this->config['ppde_ipn_logging']),
118
			'S_PPDE_IPN_NOTIFICATION_ENABLE' => $this->check_config($this->config['ppde_ipn_notification_enable']),
119
120
			// Sandbox Settings vars
121
			'PPDE_SANDBOX_ADDRESS'           => $this->check_config($this->config['ppde_sandbox_address'], 'string', ''),
122
			'S_PPDE_SANDBOX_ENABLE'          => $this->check_config($this->config['ppde_sandbox_enable']),
123
			'S_PPDE_SANDBOX_FOUNDER_ENABLE'  => $this->check_config($this->config['ppde_sandbox_founder_enable']),
124
		]);
125
	}
126
127
	/**
128
	 * Set the options a user can configure
129
	 *
130
	 * @return void
131
	 * @access protected
132
	 */
133
	protected function set_settings()
134
	{
135
		// Set options for PayPal IPN
136
		$this->config->set('ppde_ipn_autogroup_enable', $this->request->variable('ppde_ipn_autogroup_enable', false));
137
		$this->config->set('ppde_ipn_dl_allow_guest', $this->request->variable('ppde_ipn_dl_allow_guest', false));
138
		$this->config->set('ppde_ipn_donorlist_enable', $this->request->variable('ppde_ipn_donorlist_enable', false));
139
		$this->config->set('ppde_ipn_enable', $this->request->variable('ppde_ipn_enable', false));
140
		$this->config->set('ppde_ipn_group_as_default', $this->request->variable('ppde_ipn_group_as_default', false));
141
		$this->config->set('ppde_ipn_group_id', $this->request->variable('ppde_ipn_group_id', 0));
142
		$this->config->set('ppde_ipn_logging', $this->request->variable('ppde_ipn_logging', false));
143
		$this->config->set('ppde_ipn_min_before_group', $this->request->variable('ppde_ipn_min_before_group', 0));
144
		$this->config->set('ppde_ipn_notification_enable', $this->request->variable('ppde_ipn_notification_enable', false));
145
146
		// Set options for Sandbox Settings
147
		$this->config->set('ppde_sandbox_enable', $this->request->variable('ppde_sandbox_enable', false));
148
		$this->config->set('ppde_sandbox_founder_enable', $this->request->variable('ppde_sandbox_founder_enable', true));
149
		$this->config->set('ppde_sandbox_remote', $this->request->variable('ppde_sandbox_remote', 1));
150
151
		// Set misc settings
152
		$this->ppde_ipn_paypal->set_curl_info();
153
		$this->ppde_ipn_paypal->set_remote_detected();
154
		$this->ppde_ipn_paypal->check_tls();
155
		if (!$this->ppde_controller_main->is_ipn_requirement_satisfied())
156
		{
157
			$this->config->set('ppde_ipn_enable', (string) false);
158
			trigger_error($this->language->lang($this->lang_key_prefix . '_NOT_ENABLEABLE') . adm_back_link($this->u_action), E_USER_WARNING);
159
		};
160
161
		// Settings with dependencies are the last to be set.
162
		$this->config->set('ppde_sandbox_address', $this->required_settings($this->request->variable('ppde_sandbox_address', ''), $this->depend_on('ppde_sandbox_enable')));
163
		$this->ppde_controller_main->ppde_actions_auth->set_guest_acl();
164
	}
165
}
166