Passed
Pull Request — master (#373)
by Nic
05:55
created

Transaction::getTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\FoxyStripe\Foxy;
4
5
use Dynamic\FoxyStripe\Model\FoxyCart;
6
use SilverStripe\Core\Injector\Injectable;
7
8
/**
9
 * Class Transaction
10
 * @package Dynamic\FoxyStripe\Foxy
11
 */
12
class Transaction
13
{
14
    use Injectable;
15
16
    /**
17
     * @var
18
     */
19
    private $transaction;
20
21
    /**
22
     * Transaction constructor.
23
     * @param $data
24
     */
25
    public function __construct($transactionID, $data)
26
    {
27
        $this->setTransaction($transactionID, $data);
28
    }
29
30
    /**
31
     * @param $data
32
     * @return $this
33
     */
34
    public function setTransaction($transactionID, $data)
35
    {
36
        $decryptedData = $this->getDecryptedData($data);
37
38
        foreach ($decryptedData->transactions->transaction as $transaction) {
39
            if ($transactionID == (int)$transaction->id) {
40
                $this->transaction = $transaction;
41
                break;
42
            }
43
        }
44
45
        if (!$this->transaction) {
46
            $this->transaction = false;
47
        }
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return mixed
54
     */
55
    public function getTransaction()
56
    {
57
        return $this->transaction;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function exists()
64
    {
65
        return $this->getTransaction() != false && !empty($this->getTransaction());
66
    }
67
68
    /**
69
     * @param $data
70
     * @return \SimpleXMLElement
71
     * @throws \SilverStripe\ORM\ValidationException
72
     */
73
    private function getDecryptedData($data)
74
    {
75
        return new \SimpleXMLElement(\rc4crypt::decrypt(FoxyCart::getStoreKey(), $data));
0 ignored issues
show
Bug introduced by
It seems like Dynamic\FoxyStripe\Model\FoxyCart::getStoreKey() can also be of type false; however, parameter $pwd of rc4crypt::decrypt() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

75
        return new \SimpleXMLElement(\rc4crypt::decrypt(/** @scrutinizer ignore-type */ FoxyCart::getStoreKey(), $data));
Loading history...
76
    }
77
}
78