Completed
Pull Request — master (#241)
by
unknown
01:40
created

RecurringProfiles::createCustomSubscription()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 2
nop 5
1
<?php
2
3
namespace Srmklive\PayPal\Traits;
4
5
use Carbon\Carbon;
6
7
trait RecurringProfiles
8
{
9
    /**
10
     * Create recurring subscription on custom frequency basis.
11
     * The billing frequency is in months, i.e: if you want a monthly subscription, then your billing frequency would be 1.
12
     *
13
     * @param string $token
14
     * @param float $amount
15
     * @param string $description
16
     * @param int $billingFrequency
17
     * @param int $trialDays
18
     *
19
     * @return array
20
     */
21
    public function createCustomSubscription($token, $amount, $description, $billingFrequency, $trialDays = null)
22
    {
23
        $data = [
24
            'PROFILESTARTDATE' => Carbon::now()->toAtomString(),
25
            'DESC'             => $description,
26
            'BILLINGPERIOD'    => 'Month',
27
            'BILLINGFREQUENCY' => $billingFrequency,
28
            'AMT'              => $amount,
29
            'CURRENCYCODE'     => $this->currency,
0 ignored issues
show
Bug introduced by
The property currency 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...
30
        ];
31
32
        if (!is_null($trialDays) && is_numeric($trialDays)) {
33
            $data['TRIALBILLINGPERIOD'] = 'Day';
34
            $data['TRIALTOTALBILLINGCYCLES'] = $trialDays;
35
            $data['TRIALBILLINGFREQUENCY'] = 1;
36
            $data['TRIALAMT'] = 0;
37
        }
38
39
        return $this->createRecurringPaymentsProfile($data, $token);
0 ignored issues
show
Bug introduced by
It seems like createRecurringPaymentsProfile() 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...
40
    }
41
42
    /**
43
     * Create recurring subscription on monthly basis.
44
     *
45
     * @param string $token
46
     * @param float  $amount
47
     * @param string $description
48
     *
49
     * @return array
50
     */
51 View Code Duplication
    public function createMonthlySubscription($token, $amount, $description)
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...
52
    {
53
        $data = [
54
            'PROFILESTARTDATE' => Carbon::now()->toAtomString(),
55
            'DESC'             => $description,
56
            'BILLINGPERIOD'    => 'Month',
57
            'BILLINGFREQUENCY' => 1,
58
            'AMT'              => $amount,
59
            'CURRENCYCODE'     => $this->currency,
60
        ];
61
62
        return $this->createRecurringPaymentsProfile($data, $token);
0 ignored issues
show
Bug introduced by
It seems like createRecurringPaymentsProfile() 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...
63
    }
64
65
    /**
66
     * Create recurring subscription on yearly basis.
67
     *
68
     * @param string $token
69
     * @param float  $amount
70
     * @param string $description
71
     *
72
     * @return array
73
     */
74 View Code Duplication
    public function createYearlySubscription($token, $amount, $description)
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...
75
    {
76
        $data = [
77
            'PROFILESTARTDATE' => Carbon::now()->toAtomString(),
78
            'DESC'             => $description,
79
            'BILLINGPERIOD'    => 'Year',
80
            'BILLINGFREQUENCY' => 1,
81
            'AMT'              => $amount,
82
            'CURRENCYCODE'     => $this->currency,
83
        ];
84
85
        return $this->createRecurringPaymentsProfile($data, $token);
0 ignored issues
show
Bug introduced by
It seems like createRecurringPaymentsProfile() 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...
86
    }
87
}
88