DpsPxPayStoredPayment::processPayment()   D
last analyzed

Complexity

Conditions 10
Paths 48

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 20
nc 48
nop 2
dl 0
loc 31
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 *@author nicolaas [at] sunny side up. co . nz
5
 *
6
 *
7
 **/
8
9
10
class DpsPxPayStoredPayment extends DpsPxPayPayment
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...
11
{
12
    private static $pxaccess_url = 'https://sec.paymentexpress.com/pxpay/pxaccess.aspx';
0 ignored issues
show
Unused Code introduced by
The property $pxaccess_url is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
14
    private static $pxpost_url = 'https://sec.paymentexpress.com/pxpost.aspx';
0 ignored issues
show
Unused Code introduced by
The property $pxpost_url is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
16
    private static $username = '';
0 ignored issues
show
Unused Code introduced by
The property $username is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
    private static $password = '';
0 ignored issues
show
Unused Code introduced by
The property $password is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
20
    private static $add_card_explanation = "Storing a Card means your Credit Card will be kept on file for your next purchase. ";
0 ignored issues
show
Unused Code introduced by
The property $add_card_explanation is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
22
    public function getPaymentFormFields()
23
    {
24
        $logo = '<img src="' . self::$logo . '" alt="Credit Card Payments Powered by DPS"/>';
0 ignored issues
show
Documentation introduced by
The property $logo is declared private in DpsPxPayPayment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
25
        $privacyLink = '<a href="' . self::$privacy_link . '" target="_blank" title="Read DPS\'s privacy policy">' . $logo . '</a><br/>';
0 ignored issues
show
Documentation introduced by
The property $privacy_link is declared private in DpsPxPayPayment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
26
        $paymentsList = '';
27
        foreach (self::$credit_cards as $name => $image) {
0 ignored issues
show
Documentation introduced by
The property $credit_cards is declared private in DpsPxPayPayment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
28
            $paymentsList .= '<img src="' . $image . '" alt="' . $name . '"/>';
29
        }
30
31
        $fields = new FieldList();
32
        $storedCards = null;
33
        if ($m = Member::currentUser()) {
34
            $storedCards = DpsPxPayStoredCard::get()->filter(array("MemberID" => $m->ID));
35
        }
36
37
        $cardsDropdown = array('' => ' --- Select Stored Card ---');
38
39
        if ($storedCards->count()) {
40
            foreach ($storedCards as $card) {
0 ignored issues
show
Bug introduced by
The expression $storedCards of type object<DataList>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
41
                $cardsDropdown[$card->BillingID] = $card->CardHolder.' - '.$card->CardNumber.' ('.$card->CardName.')';
42
            }
43
            $s = "";
44
            if ($storedCards->count()>1) {
45
                $s = "s";
46
            }
47
            $cardsDropdown["deletecards"] = " --- Delete Stored Card$s --- ";
48
            $fields->push(new DropdownField('DPSUseStoredCard', 'Use a stored card?', $cardsDropdown, $value = $card->BillingID, $form = null, $emptyString = "--- use new Credit Card ---"));
0 ignored issues
show
Bug introduced by
The variable $card seems to be defined by a foreach iteration on line 40. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
49
        } else {
50
            $fields->push(new DropdownField('DPSStoreCard', '', array(1 => 'Store Credit Card', 0 => 'Do NOT Store Credit Card')));
51
            $fields->push(new LiteralField("AddCardExplanation", "<p>".Config::inst()->get('DpsPxPayStoredPayment', 'add_card_explanation')."</p>"));
52
        }
53
        $fields->push(new LiteralField('DPSInfo', $privacyLink));
54
        $fields->push(new LiteralField('DPSPaymentsList', $paymentsList));
55
        Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
56
        //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js");
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
57
        //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
58
        Requirements::javascript("payment_dps/javascript/DpxPxPayStoredPayment.js");
59
        return $fields;
60
    }
61
62
    public function autoProcessPayment($amount, $ref)
63
    {
64
        $DPSUrl = $this->buildURL($amount, $ref, false);
0 ignored issues
show
Unused Code introduced by
$DPSUrl 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...
65
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% 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...
66
        add CURL HERE
67
        $data = array('page' => $page);
68
        // create our curl object
69
        $ch = curl_init();
70
        $lurl = 'http://www.test.com';
71
        curl_setopt( $ch, CURLOPT_POST, true );
72
        curl_setopt( $ch, CURLOPT_POSTFIELDS,$data);
73
        curl_setopt($ch, CURLOPT_URL, $lurl);
74
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
75
        curl_setopt($ch, CURLOPT_HEADER, 0);
76
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
77
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
78
        curl_setopt($ch, CURLOPT_FAILONERROR, 0);
79
        $content = curl_exec($ch);
80
        curl_close($ch);
81
        return $content;
82
        */
83
    }
84
85
    /**
86
     * @param array $data The form request data - see OrderForm
87
     * @param OrderForm $form The form object submitted on
88
     *
89
     * @return EcommercePayment_Result
90
     */
91
    public function processPayment($data, $form)
92
    {
93
        if (!isset($data["DPSUseStoredCard"])) {
94
            $data["DPSUseStoredCard"] = null;
95
        }
96
        if (!isset($data["DPSStoreCard"])) {
97
            $data["DPSStoreCard"] = null;
98
        }
99
        if (!isset($data["Amount"])) {
100
            USER_ERROR("There was no amount information for processing the payment.", E_USER_WARNING);
101
        }
102
        if ($data["DPSUseStoredCard"] == "deletecards") {
103
            //important!!!
104
            $data["DPSUseStoredCard"] = null;
105
            if ($m = Member::currentUser()) {
106
                $storedCards = DpsPxPayStoredCard::get()->filter(array("MemberID" => $m->ID));
107
                if ($storedCards->count()) {
108
                    foreach ($storedCards as $card) {
109
                        $card->delete();
110
                    }
111
                    if ($storedCards = DpsPxPayStoredCard::get()->filter(array("MemberID" => $m->ID))) {
0 ignored issues
show
Unused Code introduced by
$storedCards 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...
112
                        DB::query("DELETE FROM DpsPxPayStoredCard WHERE MemberID = ".$m->ID);
113
                    }
114
                }
115
            }
116
        } elseif ($data["DPSUseStoredCard"]) {
117
            return $this->processViaPostRatherThanPxPay($data, $form, $data["DPSUseStoredCard"]);
118
        }
119
        $url = $this->buildURL($data["Amount"], $data["DPSUseStoredCard"], $data["DPSStoreCard"]);
120
        return $this->executeURL($url);
121
    }
122
123
124
125
126
    public function processViaPostRatherThanPxPay($data, $form, $cardToUse)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
127
    {
128
129
        // 1) Main Settings
130
131
        $inputs['PostUsername'] = $this->config->get("username");
0 ignored issues
show
Documentation introduced by
The property config does not exist on object<DpsPxPayStoredPayment>. 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...
Coding Style Comprehensibility introduced by
$inputs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $inputs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
132
        $inputs['PostPassword'] = $this->config->get("password");
0 ignored issues
show
Documentation introduced by
The property config does not exist on object<DpsPxPayStoredPayment>. 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...
133
134
        // 2) Payment Informations
135
136
        $inputs['Amount'] = $this->Amount->Amount;
0 ignored issues
show
Documentation introduced by
The property Amount does not exist on object<DpsPxPayStoredPayment>. 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...
137
        $inputs['InputCurrency'] = $this->Amount->Currency;
0 ignored issues
show
Documentation introduced by
The property Amount does not exist on object<DpsPxPayStoredPayment>. 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...
138
        $inputs['TxnId'] = $this->ID;
139
        $inputs['TxnType'] = DpsPxPayComs::get_txn_type();
140
        $inputs["MerchantReference"] = $this->ID;
141
142
        // 3) Credit Card Informations
143
        $inputs["DpsBillingId"] = $cardToUse;
144
145
146
        // 4) DPS Transaction Sending
147
148
        $responseFields = $this->doPayment($inputs);
149
        // 5) DPS Response Management
150
151
        if (isset($responseFields['SUCCESS']) && $responseFields['SUCCESS']) {
152
            $this->Status = 'Success';
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<DpsPxPayStoredPayment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
153
            $result = EcommercePayment_Success::create();
154
        } else {
155
            $this->Status = 'Failure';
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<DpsPxPayStoredPayment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
156
            $result = EcommercePayment_Failure::create();
157
        }
158
        if (isset($responseFields['DPSTXNREF'])) {
159
            if ($transactionRef = $responseFields['DPSTXNREF']) {
160
                $this->TxnRef = $transactionRef;
0 ignored issues
show
Documentation introduced by
The property TxnRef does not exist on object<DpsPxPayStoredPayment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
161
            }
162
        }
163
164
        if (isset($responseFields['HELPTEXT'])) {
165
            if ($helpText = $responseFields['HELPTEXT']) {
166
                $this->Message = $helpText;
0 ignored issues
show
Documentation introduced by
The property Message does not exist on object<DpsPxPayStoredPayment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
167
            }
168
        }
169
        if (isset($responseFields['RESPONSETEXT'])) {
170
            if ($responseText = $responseFields['RESPONSETEXT']) {
171
                $this->Message .= $responseText;
0 ignored issues
show
Documentation introduced by
The property Message does not exist on object<DpsPxPayStoredPayment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
172
            }
173
        }
174
175
        $this->write();
176
        return $result;
177
    }
178
179
    public function doPayment(array $inputs)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
180
    {
181
182
        // 1) Transaction Creation
183
        $transaction = "<Txn>";
184
        foreach ($inputs as $name => $value) {
185
            if ($name == "Amount") {
186
                $value = number_format($value, 2, '.', '');
187
            }
188
            $transaction .= "<$name>$value</$name>";
189
        }
190
        $transaction .= "</Txn>";
191
192
        // 2) CURL Creation
193
        $clientURL = curl_init();
194
        curl_setopt($clientURL, CURLOPT_URL, $this->config()-get("pxpost_url"));
195
        curl_setopt($clientURL, CURLOPT_POST, 1);
196
        curl_setopt($clientURL, CURLOPT_POSTFIELDS, $transaction);
197
        curl_setopt($clientURL, CURLOPT_RETURNTRANSFER, 1);
198
        //curl_setopt($clientURL, CURLOPT_SSLVERSION, 3);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
199
200
        // 3) CURL Execution
201
202
        $resultXml = curl_exec($clientURL);
203
204
        // 4) CURL Closing
205
206
        curl_close($clientURL);
207
208
        // 5) XML Parser Creation
209
210
        $xmlParser = xml_parser_create();
211
        $values = null;
212
        $indexes = null;
213
        xml_parse_into_struct($xmlParser, $resultXml, $values, $indexes);
214
        xml_parser_free($xmlParser);
215
216
        // 6) XML Result Parsed In A PHP Array
217
218
        $resultPhp = array();
219
        $level = array();
220
        foreach ($values as $xmlElement) {
221
            if ($xmlElement['type'] == 'open') {
222
                if (array_key_exists('attributes', $xmlElement)) {
223
                    $arrayValues = array_values($xmlElement['attributes']);
224
                    list($level[$xmlElement['level']], $extra) = $arrayValues;
0 ignored issues
show
Unused Code introduced by
The assignment to $extra is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
225
                } else {
226
                    $level[$xmlElement['level']] = $xmlElement['tag'];
227
                }
228
            } elseif ($xmlElement['type'] == 'complete') {
229
                $startLevel = 1;
230
                $phpArray = '$resultPhp';
231
                while ($startLevel < $xmlElement['level']) {
232
                    $phpArray .= '[$level['. $startLevel++ .']]';
233
                }
234
                $phpArray .= '[$xmlElement[\'tag\']] = array_key_exists(\'value\', $xmlElement)? $xmlElement[\'value\'] : null;';
235
                eval($phpArray);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
236
            }
237
        }
238
        if (!isset($resultPhp['TXN'])) {
239
            return false;
240
        }
241
        $result = $resultPhp['TXN'];
242
        return $result;
243
    }
244
245
246
247
    protected function buildURL($amount, $cardToUse = '', $storeCard = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
248
    {
249
        $commsObject = new DpsPxPayComs();
250
251
        /**
252
        * order details
253
        **/
254
        $commsObject->setTxnType(DpsPxPayComs::get_txn_type());
255
        $commsObject->setMerchantReference($this->ID);
256
        //replace any character that is NOT [0-9] or dot (.)
257
        $commsObject->setAmountInput(floatval(preg_replace("/[^0-9\.]/", "", $amount)));
258
259
        if (isset($cardToUse)) {
260
            $commsObject->setBillingId($cardToUse);
261
        } elseif ($storeCard) {
262
            $commsObject->setEnableAddBillCard(1);
263
        }
264
265
        /**
266
        * details of the redirection
267
        **/
268
        $link = DpsPxPayStoredPayment_Handler::absolute_complete_link();
269
        $commsObject->setUrlFail($link);
270
        $commsObject->setUrlSuccess($link);
271
272
        /**
273
        * process payment data (check if it is OK and go forward if it is...
274
        **/
275
        $url = $commsObject->startPaymentProcess();
276
277
        return $url;
278
    }
279
}
280