EcommercePayment_Stripe_ChargeRecordedCustomer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 69.35 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 43
loc 62
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B processPayment() 43 43 6

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
 * "Abstract" class for a number of different payment
4
 * types allowing a user to pay for something on a site.
5
 *
6
 *
7
 * This can't be an abstract class because sapphire doesn't
8
 * support abstract DataObject classes.
9
 *
10
 * @package payment
11
 */
12
class EcommercePayment_Stripe_ChargeRecordedCustomer extends EcommercePayment_Stripe
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...
13
{
14
15
    /**
16
     * Perform payment processing for the type of
17
     * payment. For example, if this was a credit card
18
     * payment type, you would perform the data send
19
     * off to the payment gateway on this function for
20
     * your payment subclass.
21
     *
22
     * This is used by {@link OrderForm} when it is
23
     * submitted.
24
     *
25
     * @param array $data The form request data - see OrderForm
26
     * @param OrderForm $form The form object submitted on
27
     *
28
     * @return EcommercePaymentResult
0 ignored issues
show
Documentation introduced by
Should the return type not be EcommercePayment_Success|EcommercePayment_Failure?

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...
29
     */
30 View Code Duplication
    public function processPayment($data, $form)
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...
31
    {
32
        //get variables
33
        $responseData = null;
34
        //get variables
35
        $this->retrieveVariables();
36
        $this->instantiateAPI();
37
        //less than fifty cents then it is fine ...
38
        if ($this->_processing_amount < 50) {
39
            $this->Status = "Success";
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<EcommercePayment_...ChargeRecordedCustomer>. 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...
40
            $returnObject = EcommercePayment_Success::create();
0 ignored issues
show
Unused Code introduced by
$returnObject 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...
41
        } elseif ($this->_processing_member && $this->_processing_member->CreditCardHasBeenRecorded()) {
0 ignored issues
show
Documentation introduced by
The property _processing_member does not exist on object<EcommercePayment_...ChargeRecordedCustomer>. 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...
42
            //if currency has been pre-set use this
43
            $requestData = array(
44
                'customer' => $this->_processing_member->StripeCustomerID,
0 ignored issues
show
Documentation introduced by
The property _processing_member does not exist on object<EcommercePayment_...ChargeRecordedCustomer>. 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...
45
                'amount' => $this->_processing_amount,
46
                'currency' => $this->_processing_currency,
47
                'capture' => true,
48
                'statement_descriptor' => $this->_processing_statement_description,
49
                'metadata' => $this->_processing_metadata
50
            );
51
            $responseData = \Stripe\Charge::create($requestData, $this->_processing_idempotency_key);
0 ignored issues
show
Documentation introduced by
The property _processing_idempotency_key does not exist on object<EcommercePayment_...ChargeRecordedCustomer>. 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...
52
            $this->removeCardDetails();
53
54
            //save basic info
55
            $this->recordTransaction($requestData, $responseData);
56
57
            //no idea why we need this!!!
58
            $this->Amount->Amount = $this->_processing_amount / 100;
0 ignored issues
show
Bug introduced by
The property Amount does not seem to exist. Did you mean _processing_amount?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
59
        }
60
        if (
61
            $responseData &&
62
            $responseData->status == "succeeded"
63
        ) {
64
            $this->Status = "Success";
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<EcommercePayment_...ChargeRecordedCustomer>. 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...
65
            $returnObject = EcommercePayment_Success::create();
66
        } else {
67
            $this->Status = "Failure";
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<EcommercePayment_...ChargeRecordedCustomer>. 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...
68
            $returnObject = EcommercePayment_Failure::create();
69
        }
70
        $this->write();
71
        return $returnObject;
72
    }
73
}
74