Completed
Push — master ( 00e474...9d3fbd )
by Michael
04:26
created

Oledrion_paypal   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 307
Duplicated Lines 9.77 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 30
loc 307
rs 9.2
c 0
b 0
f 0
wmc 34
lcom 1
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setGatewayInformation() 12 12 1
A getParametersForm() 0 49 1
A saveParametersForm() 0 14 3
A formatAmount() 0 4 1
A getRedirectURL() 9 9 2
B getCheckoutFormContent() 0 33 3
A getCountriesList() 0 6 1
A getdialogURL() 9 9 2
D gatewayNotify() 0 98 19

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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link http://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
/**
21
 * Paypal Gateway
22
 */
23
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
25
class Oledrion_paypal extends Oledrion_gateway
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
26
{
27
    /**
28
     * Oledrion_paypal constructor.
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Retourne des informations sur la passerelle de paiement
37
     *
38
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40 View Code Duplication
    public function setGatewayInformation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
41
    {
42
        $gateway                  = array();
43
        $gateway['name']          = 'Paypal';
44
        $gateway['foldername']    = 'paypal';
45
        $gateway['version']       = '1.1';
46
        $gateway['description']   = 'PayPal is the safer, easier way to pay and get paid online';
47
        $gateway['author']        = 'Instant Zero (http://www.herve-thouzard.com/)';
48
        $gateway['credits']       = 'Hervé Thouzard';
49
        $gateway['releaseDate']   = 20081215;
50
        $this->gatewayInformation = $gateway;
51
    }
52
53
    /**
54
     * Retourne le formulaire utilisé pour paramétrer la passerelle de paiement
55
     *
56
     * @param $postUrl
57
     * @return object de type XoopsThemeForm
58
     */
59
    public function getParametersForm($postUrl)
60
    {
61
        require $this->getGatewayLanguageFile();
62
63
        $sform = new XoopsThemeForm(_OLEDRION_PAYPAL_PARAMETERS . ' - ' . $this->gatewayInformation['name'], 'frmPaypal', $postUrl);
64
        // You must specify the gateway folder's name
65
        $sform->addElement(new XoopsFormHidden('gateway', $this->gatewayInformation['foldername']));
66
67
        // Adresse email Paypal du compte marchand
68
        $paypal_email = new XoopsFormText(_OLEDRION_PAYPAL_EMAIL, 'paypal_email', 50, 255, $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($this->gatewayInformation['foldername'], 'paypal_email'));
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
69
        $paypal_email->setDescription(_OLEDRION_PAYPAL_EMAILDSC);
70
        $sform->addElement($paypal_email, true);
71
72
        // Libellé de la monnaie pour Paypal
73
        $paypal_money = new XoopsFormSelect(_OLEDRION_PAYPAL_MONEY_P, 'paypal_money', $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($this->gatewayInformation['foldername'], 'paypal_money'));
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
74
        $paypal_money->addOptionArray(array(
75
                                          'AUD' => 'Australian Dollar',
76
                                          'CAD' => 'Canadian Dollar',
77
                                          'CHF' => 'Swiss Franc',
78
                                          'CZK' => 'Czech Koruna',
79
                                          'DKK' => 'Danish Krone',
80
                                          'EUR' => 'Euro',
81
                                          'GBP' => 'Pound Sterling',
82
                                          'HKD' => 'Hong Kong Dollar',
83
                                          'HUF' => 'Hungarian Forint',
84
                                          'JPY' => 'Japanese Yen',
85
                                          'NOK' => 'Norwegian Krone',
86
                                          'NZD' => 'New Zealand Dollar',
87
                                          'PLN' => 'Polish Zloty',
88
                                          'SEK' => 'Swedish Krona',
89
                                          'SGD' => 'Singapore Dollar',
90
                                          'USD' => 'U.S. Dollar'
91
                                      ));
92
        $sform->addElement($paypal_money, true);
93
94
        // Paypal en mode test ?
95
        $paypal_test = new XoopsFormRadioYN(_OLEDRION_PAYPAL_TEST, 'paypal_test', $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($this->gatewayInformation['foldername'], 'paypal_test'));
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
96
        $sform->addElement($paypal_test, true);
97
98
        // Forcé à vrai ...
99
        $sform->addElement(new XoopsFormHidden('use_ipn', 1));
100
101
        $button_tray = new XoopsFormElementTray('', '');
102
        $submit_btn  = new XoopsFormButton('', 'post', _AM_OLEDRION_GATEWAYS_UPDATE, 'submit');
103
        $button_tray->addElement($submit_btn);
104
        $sform->addElement($button_tray);
105
106
        return $sform;
107
    }
108
109
    /**
110
     * Sauvegarde des paramètres de la passerelle de paiement
111
     *
112
     * @param  array $data Les données du formulaire
113
     * @return boolean Le résultat de l'enregistrement des données
114
     */
115
    public function saveParametersForm($data)
116
    {
117
        $parameters = array('paypal_email', 'paypal_money', 'paypal_test', 'use_ipn');
118
        // On commence par supprimer les valeurs actuelles
119
        $gatewayName = $this->gatewayInformation['foldername'];
120
        $this->handlers->h_oledrion_gateways_options->deleteGatewayOptions($gatewayName);
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
        foreach ($parameters as $parameter) {
122
            if (!$this->handlers->h_oledrion_gateways_options->setGatewayOptionValue($gatewayName, $parameter, $data[$parameter])) {
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
123
                return false;
124
            }
125
        }
126
127
        return true;
128
    }
129
130
    /**
131
     * Formate le montant au format Paypal
132
     * @param $amount
133
     * @return string
134
     */
135
    private function formatAmount($amount)
136
    {
137
        return number_format($amount, 2, '.', '');
138
    }
139
140
    /**
141
     * Retourne l'url vers laquelle rediriger l'utilisateur pour le paiement en ligne
142
     *
143
     * @param $cmd_total
144
     * @param $cmd_id
145
     * @return string
146
     */
147 View Code Duplication
    public function getRedirectURL($cmd_total, $cmd_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
148
    {
149
        $test_mode = (int)$this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($this->gatewayInformation['foldername'], 'paypal_test');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
150
        if ($test_mode == 1) {
151
            return 'https://www.sandbox.paypal.com/cgi-bin/webscr';
152
        } else {
153
            return 'https://www.paypal.com/cgi-bin/webscr';
154
        }
155
    }
156
157
    /**
158
     * Retourne les éléments à ajouter au formulaire en tant que zones cachées
159
     *
160
     * @param array $order La commande client
161
     * @param       array
162
     * @return array
163
     */
164
    public function getCheckoutFormContent($order)
165
    {
166
        global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
167
        $gatewayName  = $this->gatewayInformation['foldername'];
168
        $paypal_money = $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($gatewayName, 'paypal_money');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
169
        $paypal_email = $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($gatewayName, 'paypal_email');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
170
        $use_ipn      = (int)$this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($gatewayName, 'use_ipn');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
171
172
        $ret                     = array();
173
        $ret['cmd']              = '_xclick';
174
        $ret['upload']           = '1';
175
        $ret['currency_code']    = $paypal_money;
176
        $ret['business']         = $paypal_email;
177
        $ret['return']           = OLEDRION_URL . 'thankyou.php'; // Page (générique) de remerciement après paiement
178
        $ret['image_url']        = XOOPS_URL . '/images/logo.gif';
179
        $ret['cpp_header_image'] = XOOPS_URL . '/images/logo.gif';
180
        $ret['invoice']          = $order->getVar('cmd_id');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
181
        $ret['item_name']        = _OLEDRION_COMMAND . $order->getVar('cmd_id') . ' - ' . Oledrion_utils::makeHrefTitle($xoopsConfig['sitename']);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
182
        $ret['item_number']      = $order->getVar('cmd_id');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
183
        $ret['tax']              = 0; // ajout 25/03/2008
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
184
        $ret['amount']           = $this->formatAmount((float)$order->getVar('cmd_total', 'n'));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
185
        $ret['custom']           = $order->getVar('cmd_id');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
186
        //$ret['rm'] = 2;   // Renvoyer les données par POST (normalement)
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
187
        $ret['email'] = $order->getVar('cmd_email');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
188
        if (xoops_trim($order->getVar('cmd_cancel')) != '') { // URL à laquelle le navigateur du client est ramené si le paiement est annulé
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
189
            $ret['cancel_return'] = OLEDRION_URL . 'cancel-payment.php?id=' . $order->getVar('cmd_cancel');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $order (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
190
        }
191
        if ($use_ipn == 1) {
192
            $ret['notify_url'] = OLEDRION_URL . 'gateway-notify.php'; // paypal-notify.php
193
        }
194
195
        return $ret;
196
    }
197
198
    /**
199
     * Retourne la liste des pays à utiliser dans le formulaire de saisie des informations client (checkout.php)
200
     *
201
     * @return array
202
     */
203
    public function getCountriesList()
204
    {
205
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
206
207
        return XoopsLists::getCountryList();
208
    }
209
210
    /**
211
     * Utilisée lors du dialog avec Paypal dans le cas de l'utilisation de l'IPN
212
     * Note : Spécifique Paypal
213
     *
214
     * @return string L'URL chez Paypal à appeler pour obtenir des informations
215
     */
216 View Code Duplication
    private function getdialogURL()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
217
    {
218
        $test_mode = (int)$this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($this->gatewayInformation['foldername'], 'paypal_test');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
219
        if ($test_mode == 1) {
220
            return 'www.sandbox.paypal.com';
221
        } else {
222
            return 'www.paypal.com';
223
        }
224
    }
225
226
    /**
227
     * Dialogue avec la passerelle de paiement pour indiquer l'état de la commande
228
     * L'appellant se charge de vérifier que le fichier log existe
229
     *
230
     * @param  string $gatewaysLogPath Le chemin d'accès complet au fichier log
231
     * @return void
232
     */
233
    public function gatewayNotify($gatewaysLogPath)
0 ignored issues
show
Coding Style introduced by
gatewayNotify uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
234
    {
235
        error_reporting(0);
236
        @$xoopsLogger->activated = false;
0 ignored issues
show
Bug introduced by
The variable $xoopsLogger does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
237
238
        $log     = '';
239
        $req     = 'cmd=_notify-validate';
240
        $slashes = get_magic_quotes_gpc();
241
        foreach ($_POST as $key => $value) {
242
            if ($slashes) {
243
                $log .= "$key=" . stripslashes($value) . "\n";
244
                $value = urlencode(stripslashes($value));
245
            } else {
246
                $log .= "$key=" . $value . "\n";
247
                $value = urlencode($value);
248
            }
249
            $req .= "&$key=$value";
250
        }
251
        $url          = $this->getdialogURL();
252
        $gatewayName  = $this->gatewayInformation['foldername'];
253
        $paypal_email = $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($gatewayName, 'paypal_email');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
254
        $paypal_money = $this->handlers->h_oledrion_gateways_options->getGatewayOptionValue($gatewayName, 'paypal_money');
0 ignored issues
show
Documentation introduced by
The property h_oledrion_gateways_options does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
255
        $header       = '';
256
        $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
257
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
258
        $header .= 'Content-Length: ' . strlen($req) . "\r\n\r\n";
259
        $errno  = 0;
260
        $errstr = '';
261
        $fp     = fsockopen($url, 80, $errno, $errstr, 30);
262
        if ($fp) {
263
            fwrite($fp, "$header$req");
264
            while (!feof($fp)) {
265
                $res = fgets($fp, 1024);
266
                if (strcmp($res, 'VERIFIED') == 0) {
267
                    $log .= "VERIFIED\t";
268
                    $paypalok = true;
269
                    if (strtoupper($_POST['payment_status']) !== 'COMPLETED') {
270
                        $paypalok = false;
271
                    }
272
                    if (strtoupper($_POST['receiver_email']) != strtoupper($paypal_email)) {
273
                        $paypalok = false;
274
                    }
275
                    if (strtoupper($_POST['mc_currency']) != strtoupper($paypal_money)) {
276
                        $paypalok = false;
277
                    }
278
                    if (!$_POST['custom']) {
279
                        $paypalok = false;
280
                    }
281
                    $montant = $_POST['mc_gross'];
282
                    if ($paypalok) {
283
                        $ref      = (int)$_POST['custom']; // Numéro de la commande
284
                        $commande = null;
0 ignored issues
show
Unused Code introduced by
$commande is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
285
                        $commande = $this->handlers->h_oledrion_commands->get($ref);
0 ignored issues
show
Documentation introduced by
The property h_oledrion_commands does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
286
                        if (is_object($commande)) {
287
                            if ($montant == $commande->getVar('cmd_total')) { // Commande vérifiée
288
                                $this->handlers->h_oledrion_commands->validateOrder($commande); // Validation de la commande et mise à jour des stocks
0 ignored issues
show
Documentation introduced by
The property h_oledrion_commands does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
289
                            } else {
290
                                $this->handlers->h_oledrion_commands->setFraudulentOrder($commande);
0 ignored issues
show
Documentation introduced by
The property h_oledrion_commands does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
291
                            }
292
                        }
293
                    } else {
294
                        if (isset($_POST['custom'])) {
295
                            $ref      = (int)$_POST['custom'];
296
                            $commande = null;
0 ignored issues
show
Unused Code introduced by
$commande is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
297
                            $commande = $this->handlers->h_oledrion_commands->get($ref);
0 ignored issues
show
Documentation introduced by
The property h_oledrion_commands does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
298
                            if (is_object($commande)) {
299
                                switch (strtoupper($_POST['payment_status'])) {
300
                                    case 'PENDING':
301
                                        $this->handlers->h_oledrion_commands->setOrderPending($commande);
0 ignored issues
show
Documentation introduced by
The property h_oledrion_commands does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
302
                                        break;
303
                                    case 'FAILED':
304
                                        $this->handlers->h_oledrion_commands->setOrderFailed($commande);
0 ignored issues
show
Documentation introduced by
The property h_oledrion_commands does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
305
                                        break;
306
                                }
307
                            }
308
                        }
309
                    }
310
                } else {
311
                    $log .= "$res\n";
312
                }
313
            }
314
            fclose($fp);
315
        } else {
316
            $log .= "Error with the fsockopen function, unable to open communication ' : ($errno) $errstr\n";
317
        }
318
319
        // Ecriture dans le fichier log
320
        $fp = fopen($gatewaysLogPath, 'a');
321
        if ($fp) {
322
            fwrite($fp, str_repeat('-', 120) . "\n");
323
            fwrite($fp, date('d/m/Y H:i:s') . "\n");
324
            if (isset($_POST['txn_id'])) {
325
                fwrite($fp, 'Transaction : ' . $_POST['txn_id'] . "\n");
326
            }
327
            fwrite($fp, 'Result : ' . $log . "\n");
328
            fclose($fp);
329
        }
330
    }
331
}
332