Skip to content

Commit

Permalink
Small code changes and PHPDocs update
Browse files Browse the repository at this point in the history
  • Loading branch information
Skouat committed Oct 17, 2024
1 parent 3d16dd9 commit cfa84ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 58 deletions.
3 changes: 0 additions & 3 deletions acp/ppde_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ppde_module
*
* @return void
* @throws \Exception
* @access public
*/
public function main($id, $mode)
{
Expand Down Expand Up @@ -82,7 +81,6 @@ public function main($id, $mode)
*
* @return void
* @throws \Exception
* @access private
*/
private function switch_mode($id, $mode, $admin_controller): void
{
Expand Down Expand Up @@ -136,7 +134,6 @@ private function switch_mode($id, $mode, $admin_controller): void
*
* @return void
* @throws \Exception
* @access private
*/
private function do_action($action, $controller): void
{
Expand Down
70 changes: 26 additions & 44 deletions controller/ipn_paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@

class ipn_paypal
{
/**
* Args from PayPal notify return URL
*
* @var string
*/
private $args_return_uri = [];
/** Production and Sandbox Postback URL
*
* @var array
*/
/** @var array Production and Sandbox Postback URL */
private static $remote_uri = [
['hostname' => 'www.paypal.com', 'uri' => 'https://www.paypal.com/cgi-bin/webscr', 'type' => 'live'],
['hostname' => 'www.sandbox.paypal.com', 'uri' => 'https://www.sandbox.paypal.com/cgi-bin/webscr', 'type' => 'sandbox'],
Expand All @@ -40,38 +31,24 @@ class ipn_paypal
protected $language;
protected $ppde_ipn_log;
protected $request;
/**
* @var array
*/
/** @var string Args from PayPal notify return URL */
private $args_return_uri;
/** @var array */
private $curl_fsock = ['curl' => false, 'none' => true];
/**
* @var array
*/

/** @var array */
private $postback_args = [];
/**
* Full PayPal response for include in text report
*
* @var string
*/

/** @var string Full PayPal response for include in text report */
private $report_response = '';
/**
* PayPal response (VERIFIED or INVALID)
*
* @var string
*/

/** @var string PayPal response (VERIFIED or INVALID) */
private $response = '';
/**
* PayPal response status (code 200 or other)
*
* @var string
*/

/** @var string PayPal response status (code 200 or other) */
private $response_status = '';
/**
* PayPal URL
* Could be Sandbox URL ou normal PayPal URL.
*
* @var string
*/

/** @var string PayPal URL (Could be Sandbox URL or normal PayPal URL) */
private $u_paypal = '';

/**
Expand Down Expand Up @@ -114,7 +91,7 @@ public static function get_remote_uri(): array
* @return void
* @access public
*/
public function initiate_paypal_connection($data): void
public function initiate_paypal_connection(array $data): void
{
if ($this->curl_fsock['curl'])
{
Expand All @@ -125,7 +102,12 @@ public function initiate_paypal_connection($data): void
$this->log_paypal_connection_error($data);
}

private function log_paypal_connection_error($data): void
/**
* Log PayPal connection error
*
* @param array $data
*/
private function log_paypal_connection_error(array $data): void
{
$this->ppde_ipn_log->log_error(
$this->language->lang('NO_CONNECTION_DETECTED'),
Expand All @@ -148,7 +130,7 @@ private function log_paypal_connection_error($data): void
* @return void
* @access private
*/
private function curl_post($encoded_data): void
private function curl_post(string $encoded_data): void
{
$ch = $this->init_curl_session($encoded_data);
$this->valuate_response(curl_exec($ch), $ch);
Expand All @@ -167,7 +149,7 @@ private function curl_post($encoded_data): void
* @return resource Returns a cURL session handle on success, false on failure.
* @access private
*/
private function init_curl_session($encoded_data)
private function init_curl_session(string $encoded_data)
{
$ch = curl_init($this->u_paypal);

Expand Down Expand Up @@ -271,9 +253,9 @@ public function is_remote_detected(): bool
* @return void
* @access public
*/
public function set_u_paypal($u_paypal): void
public function set_u_paypal(string $u_paypal): void
{
$this->u_paypal = (string) $u_paypal;
$this->u_paypal = $u_paypal;
}

/**
Expand Down Expand Up @@ -340,7 +322,7 @@ public function check_response_status(): bool
* @return bool
* @access public
*/
public function is_curl_strcmp($arg): bool
public function is_curl_strcmp(string $arg): bool
{
return $this->curl_fsock['curl'] && (strcmp($this->response, $arg) === 0);
}
Expand Down
17 changes: 6 additions & 11 deletions controller/main_display_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private function generate_stats_percentage(): void
{
if ($details['condition'])
{
$percentage = $this->percentage_value(
$percentage = $this->calculate_percentage(
(float) $this->config[$details['numerator']],
(float) $this->config[$details['denominator']]
);
Expand Down Expand Up @@ -214,19 +214,17 @@ private function is_ppde_used_stats(): bool
/**
* Gives back the percentage value
*
* @param float $multiplicand
* @param float $divisor
*
* @param float $numerator
* @param float $denominator
* @return float
* @access private
*/
private function percentage_value(float $multiplicand, float $divisor): float
private function calculate_percentage(float $numerator, float $denominator): float
{
if ($divisor == 0)
if ($denominator == 0)
{
return 0.0;
}
return round(($multiplicand * 100) / $divisor, 2);
return round(($numerator * 100) / $denominator, 2);
}

/**
Expand All @@ -239,9 +237,6 @@ private function percentage_value(float $multiplicand, float $divisor): float
*/
private function assign_vars_stats_percentage(string $var_name, float $percentage): void
{
// Enforcing $var_name to uppercase
$var_name = strtoupper($var_name);

$this->template->assign_vars([
'PPDE_' . $var_name => ($percentage < 100) ? $percentage : round($percentage),
'PPDE_' . $var_name . '_CSS' => max(0, min(100, $percentage)),
Expand Down

0 comments on commit cfa84ff

Please sign in to comment.