DpsPxPayStoredPayment_Handler   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A complete_link() 0 4 1
A absolute_complete_link() 0 4 1
C paid() 0 39 8
1
<?php
2
3
class DpsPxPayStoredPayment_Handler extends DpsPxPayPayment_Handler
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...
4
{
5
    private static $url_segment = 'dpspxpaystoredpayment';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_segment 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...
6
7
8
    public static function complete_link()
9
    {
10
        return Config::inst()->get('DpsPxPayStoredPayment_Handler', 'url_segment') . '/paid/';
11
    }
12
13
    public static function absolute_complete_link()
14
    {
15
        return Director::AbsoluteURL(self::complete_link());
16
    }
17
18
    public function paid()
19
    {
20
        $commsObject = new DpsPxPayComs();
21
        $response = $commsObject->processRequestAndReturnResultsAsObject();
22
        if ($payment = DpsPxPayStoredPayment::get()->byID($response->getMerchantReference())) {
23
            if ($payment->Status != 'Success') {
24
                if (1 == $response->getSuccess()) {
25
                    $payment->Status = 'Success';
26
27
                    if ($response->DpsBillingId) {
28
                        $existingCard = DpsPxPayStoredCard::get()->filter(array("BillingID" => $response->DpsBillingId))->First();
29
30
                        if ($existingCard == false) {
31
                            $storedCard = new DpsPxPayStoredCard();
32
                            $storedCard->BillingID = $response->DpsBillingId;
0 ignored issues
show
Documentation introduced by
The property BillingID does not exist on object<DpsPxPayStoredCard>. 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...
33
                            $storedCard->CardName = $response->CardName;
0 ignored issues
show
Documentation introduced by
The property CardName does not exist on object<DpsPxPayStoredCard>. 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...
34
                            $storedCard->CardHolder = $response->CardHolderName;
0 ignored issues
show
Documentation introduced by
The property CardHolder does not exist on object<DpsPxPayStoredCard>. 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...
35
                            $storedCard->CardNumber = $response->CardNumber;
0 ignored issues
show
Documentation introduced by
The property CardNumber does not exist on object<DpsPxPayStoredCard>. 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...
36
                            $storedCard->MemberID = $payment->Order()->MemberID;
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<DpsPxPayStoredCard>. 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...
37
                            $storedCard->write();
38
                        }
39
                    }
40
                } else {
41
                    $payment->Status = 'Failure';
42
                }
43
                if ($DpsTxnRef = $response->getDpsTxnRef()) {
44
                    $payment->TxnRef = $DpsTxnRef;
45
                }
46
                if ($ResponseText = $response->getResponseText()) {
47
                    $payment->Message = $ResponseText;
48
                }
49
                $payment->write();
50
            }
51
            $payment->redirectToOrder();
52
        } else {
53
            USER_ERROR("could not find payment with matching ID", E_USER_WARNING);
54
        }
55
        return;
56
    }
57
}
58