Completed
Push — master ( 4a03fb...09659a )
by Gregorio
03:13
created

HasPaymentMethodData::setRetainOnSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1.125
1
<?php
2
3
namespace Omnipay\Spreedly\Message\Concerns;
4
5
use Omnipay\Common\CreditCard;
6
use Omnipay\Common\Exception\InvalidRequestException;
7
use Omnipay\Spreedly\BankAccount;
8
9
trait HasPaymentMethodData
10
{
11
    /**
12
     * Get the bank account.
13
     *
14
     * @return BankAccount
15
     */
16 4
    public function getBankAccount()
17
    {
18 4
        return $this->getParameter('bank_account');
0 ignored issues
show
Bug introduced by
It seems like getParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19
    }
20
21
    /**
22
     * Sets the card.
23
     *
24
     * @param BankAccount $value
25
     * @return AbstractRequest Provides a fluent interface
26
     */
27 4
    public function setBankAccount($value)
28
    {
29 4
        if ($value && !$value instanceof BankAccount) {
30 4
            $value = new BankAccount($value);
31 4
        }
32
33 4
        return $this->setParameter('bank_account', $value);
0 ignored issues
show
Bug introduced by
It seems like setParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
    }
35
36
    /**
37
     * @return array
38
     * @throws InvalidRequestException
39
     * @throws \Omnipay\Common\Exception\InvalidCreditCardException
40
     * @throws \Omnipay\Spreedly\Exception\InvalidPaymentMethodException
41
     */
42 22
    protected function validateAndGetPaymentMethodData()
43
    {
44 22
        $data = array();
45
46
        // Set data depending on payment method
47 22
        if ($this->parameters->has('token')) {
48
            // Token payment method
49 12
            $data['payment_method_token'] = $this->getToken();
0 ignored issues
show
Bug introduced by
It seems like getToken() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
50 22
        } elseif ($this->parameters->has('card')) {
0 ignored issues
show
Bug introduced by
The property parameters does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
            // Card payment method
52
            /** @var CreditCard $card */
53 10
            $card = $this->getCard();
0 ignored issues
show
Bug introduced by
It seems like getCard() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
54 10
            $card->validate();
55
56 10
            $data['credit_card'] = array(
57 10
                'first_name' => $card->getFirstName(),
58 10
                'last_name' => $card->getLastName(),
59 10
                'number' => $card->getNumber(),
60 10
                'verification_value' => (string) $card->getCvv(),
61 10
                'month' => (string) $card->getExpiryMonth(),
62 10
                'year' => (string) $card->getExpiryYear(),
63
            );
64 10
        } elseif ($this->parameters->has('bank_account')) {
65
            // Bank Account payment method
66
            /** @var BankAccount $bankAccount */
67 4
            $bankAccount = $this->getBankAccount();
68 4
            $bankAccount->validate();
69
70 4
            $data['bank_account'] = array(
71 4
                'first_name' => $bankAccount->getFirstName(),
72 4
                'last_name' => $bankAccount->getLastName(),
73 4
                'bank_account_number' => (string) $bankAccount->getNumber(),
74 4
                'bank_routing_number' => (string) $bankAccount->getRoutingNumber(),
75 4
                'bank_account_type' => $bankAccount->getType(),
76 4
                'bank_account_holder_type' => $bankAccount->getHolderType(),
77
            );
78 4
        } else {
79
            // ToDo: Implement other payment methods (Android and Apple Pay...)
80
            throw new InvalidRequestException("Missing payment method.");
81
        }
82
83 22
        return $data;
84
    }
85
86 14
    public function getRetainOnSuccess()
87
    {
88 14
        return $this->getParameter('retain_on_success');
0 ignored issues
show
Bug introduced by
It seems like getParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
89
    }
90
91 6
    public function setRetainOnSuccess($value)
92
    {
93 6
        return $this->setParameter('retain_on_success', $value);
0 ignored issues
show
Bug introduced by
It seems like setParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
94
    }
95
}
96