paypal_features_controller::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 19
rs 10
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-2024 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\esi_controller;
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 esi_controller esi_controller  Extension System Information object
30
 * @property request        request         Request object
31
 * @property bool           submit          State of submit $_POST variable
32
 * @property template       template        Template object
33
 * @property string         u_action        Action URL
34
 * @property user           user            User object
35
 */
36
class paypal_features_controller extends admin_main
37
{
38
	protected $ppde_controller_main;
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 esi_controller  $esi_controller       Extension System Information 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
		esi_controller $esi_controller,
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->esi_controller = $esi_controller;
70
		$this->request = $request;
71
		$this->template = $template;
72
		$this->user = $user;
73
	}
74
75
	/**
76
	 * Display the settings a user can configure for this extension
77
	 *
78
	 * @return void
79
	 * @throws \ReflectionException
80
	 * @access public
81
	 */
82
	public function display_settings(): void
83
	{
84
		$this->ppde_first_start();
85
86
		// Define the name of the form for use as a form key
87
		add_form_key('ppde_paypal_features');
88
89
		// Create an array to collect errors that will be output to the user
90
		$errors = [];
91
92
		$this->submit_settings();
93
94
		// Set output vars for display in the template
95
		$this->s_error_assign_template_vars($errors);
96
		$this->u_action_assign_template_vars();
97
		$this->build_remote_uri_select_menu((int) $this->config['ppde_sandbox_remote'], 'sandbox');
98
99
		$this->template->assign_vars([
100
			// PayPal IPN vars
101
			'PPDE_IPN_AG_MIN_BEFORE_GROUP'   => $this->check_config($this->config['ppde_ipn_min_before_group'], 'integer', 0),
102
			'S_PPDE_IPN_AG_ENABLE'           => $this->check_config($this->config['ppde_ipn_autogroup_enable']),
103
			'S_PPDE_IPN_AG_GROUP_AS_DEFAULT' => $this->check_config($this->config['ppde_ipn_group_as_default']),
104
			'S_PPDE_IPN_DL_ALLOW_GUEST'      => $this->check_config($this->config['ppde_ipn_dl_allow_guest'], 'boolean', false),
105
			'S_PPDE_IPN_DL_ENABLE'           => $this->check_config($this->config['ppde_ipn_donorlist_enable']),
106
			'S_PPDE_IPN_ENABLE'              => $this->check_config($this->config['ppde_ipn_enable']),
107
			'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

107
			'S_PPDE_IPN_GROUP_OPTIONS'       => group_select_options(/** @scrutinizer ignore-type */ $this->config['ppde_ipn_group_id']),
Loading history...
108
			'S_PPDE_IPN_LOGGING'             => $this->check_config($this->config['ppde_ipn_logging']),
109
			'S_PPDE_IPN_NOTIFICATION_ENABLE' => $this->check_config($this->config['ppde_ipn_notification_enable']),
110
111
			// Sandbox Settings vars
112
			'PPDE_SANDBOX_ADDRESS'           => $this->check_config($this->config['ppde_sandbox_address'], 'string'),
113
			'S_PPDE_SANDBOX_ENABLE'          => $this->check_config($this->config['ppde_sandbox_enable']),
114
			'S_PPDE_SANDBOX_FOUNDER_ENABLE'  => $this->check_config($this->config['ppde_sandbox_founder_enable']),
115
		]);
116
	}
117
118
	/**
119
	 * {@inheritdoc}
120
	 */
121
	protected function set_settings(): void
122
	{
123
		// Set options for PayPal IPN
124
		$this->config->set('ppde_ipn_autogroup_enable', $this->request->variable('ppde_ipn_autogroup_enable', false));
125
		$this->config->set('ppde_ipn_dl_allow_guest', $this->request->variable('ppde_ipn_dl_allow_guest', false));
126
		$this->config->set('ppde_ipn_donorlist_enable', $this->request->variable('ppde_ipn_donorlist_enable', false));
127
		$this->config->set('ppde_ipn_enable', $this->request->variable('ppde_ipn_enable', false));
128
		$this->config->set('ppde_ipn_group_as_default', $this->request->variable('ppde_ipn_group_as_default', false));
129
		$this->config->set('ppde_ipn_group_id', $this->request->variable('ppde_ipn_group_id', 0));
130
		$this->config->set('ppde_ipn_logging', $this->request->variable('ppde_ipn_logging', false));
131
		$this->config->set('ppde_ipn_min_before_group', $this->request->variable('ppde_ipn_min_before_group', 0));
132
		$this->config->set('ppde_ipn_notification_enable', $this->request->variable('ppde_ipn_notification_enable', false));
133
134
		// Set options for Sandbox Settings
135
		$this->config->set('ppde_sandbox_enable', $this->request->variable('ppde_sandbox_enable', false));
136
		$this->config->set('ppde_sandbox_founder_enable', $this->request->variable('ppde_sandbox_founder_enable', true));
137
		$this->config->set('ppde_sandbox_remote', $this->request->variable('ppde_sandbox_remote', 1));
138
139
		// Set misc settings
140
		$this->esi_controller->set_curl_info();
141
		$this->esi_controller->set_remote_detected();
142
		$this->esi_controller->check_tls();
143
		if (!$this->ppde_controller_main->is_ipn_requirement_satisfied())
144
		{
145
			$this->config->set('ppde_ipn_enable', '');
146
			trigger_error($this->language->lang($this->lang_key_prefix . '_NOT_ENABLEABLE') . adm_back_link($this->u_action), E_USER_WARNING);
147
		}
148
149
		// Settings with dependencies are the last to be set.
150
		$this->config->set('ppde_sandbox_address', $this->required_settings($this->request->variable('ppde_sandbox_address', ''), (bool) $this->config['ppde_sandbox_enable']));
151
		$this->ppde_controller_main->ppde_auth->set_guest_acl();
152
	}
153
}
154