| Total Complexity | 9 | 
| Total Lines | 64 | 
| Duplicated Lines | 0 % | 
| Coverage | 0% | 
| Changes | 0 | ||
| 1 | <?php | ||
| 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) | ||
| 76 | } | ||
| 77 | } | ||
| 78 |