Passed
Push — master ( 1803d2...fbfbcb )
by Gabriel
06:19
created

IsPurchasableTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 6
eloc 23
c 4
b 0
f 1
dl 0
loc 78
ccs 24
cts 28
cp 0.8571
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPurchaseParametersCard() 0 3 1
A getPurchaseDate() 0 3 1
A isMultiItemPurchase() 0 3 1
A getPurchaseParameters() 0 28 1
A getPurchaseName() 0 3 1
A getPurchaseCurrency() 0 3 1
1
<?php
2
3
namespace ByTIC\Payments\Models\Purchase\Traits;
4
5
/**
6
 * Class MethodTrait
7
 * @package ByTIC\Payments\Traits
8
 */
9
trait IsPurchasableTrait
10
{
11
12
    /**
13
     * @return array
14
     */
15 7
    public function getPurchaseParameters()
16
    {
17 7
        $parameters = [];
18 7
        $parameters['amount'] = $this->getPurchaseAmount();
19 7
        $parameters['currency'] = $this->getPurchaseCurrency();
20
21 7
        $parameters['orderId'] = $this->id;
22 7
        $parameters['orderName'] = $this->getPurchaseName();
23 7
        $parameters['orderDate'] = $this->getPurchaseDate();
24
25 7
        $parameters['description'] = $this->getPurchaseName();
26 7
        $parameters['lang'] = translator()->getLanguage();
0 ignored issues
show
Deprecated Code introduced by
The function Nip\I18n\Translator::getLanguage() has been deprecated: Use getLocale instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

26
        $parameters['lang'] = /** @scrutinizer ignore-deprecated */ translator()->getLanguage();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
27
28 7
        $parameters['items'] = [
29
            [
30 7
                'name' => $this->getPurchaseName(),
31 7
                'price' => $this->getPurchaseAmount(),
32 7
                'description' => $this->getPurchaseName(),
33 7
                'quantity' => 1,
34
            ],
35
        ];
36
37 7
        $parameters['returnUrl'] = $this->getConfirmURL();
0 ignored issues
show
Bug introduced by
It seems like getConfirmURL() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        /** @scrutinizer ignore-call */ 
38
        $parameters['returnUrl'] = $this->getConfirmURL();
Loading history...
38 7
        $parameters['notifyUrl'] = $this->getIpnURL();
0 ignored issues
show
Bug introduced by
It seems like getIpnURL() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        /** @scrutinizer ignore-call */ 
39
        $parameters['notifyUrl'] = $this->getIpnURL();
Loading history...
39
40 7
        $parameters['card'] = $this->getPurchaseParametersCard();
41
42 7
        return $parameters;
43
    }
44
45
    abstract public function getPurchaseAmount();
46
47
    /**
48
     * @return string
49
     */
50 7
    public function getPurchaseCurrency()
51
    {
52 7
        return 'RON';
53
    }
54
55
    /**
56
     * @return string
57
     */
58 7
    public function getPurchaseName()
59
    {
60 7
        return $this->getName();
61
    }
62
63
    abstract public function getName();
64
65
    /**
66
     * @return string
67
     */
68 7
    public function getPurchaseDate()
69
    {
70 7
        return $this->created;
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getPurchaseParametersCard()
77
    {
78
        return null;
79
    }
80
81
    /**
82
     * @return bool
83
     */
84
    public function isMultiItemPurchase()
85
    {
86
        return false;
87
    }
88
}
89