AuthenticateResponse   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 9
c 7
b 2
f 2
lcom 1
cbo 3
dl 0
loc 102
ccs 31
cts 31
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A isSuccess() 0 3 1
A getCard() 0 3 1
A getPermanentToken() 0 3 1
A getRecurring() 0 3 1
A initializeByString() 0 14 3
A __toString() 0 18 1
1
<?php
2
/*
3
 * Copyright 2015 Alexey Maslov <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace alxmsl\PaymentNinja\Response;
19
20
use alxmsl\PaymentNinja\InitializationInterface;
21
22
/**
23
 * Class for card's authentication data
24
 * @author alxmsl
25
 */
26
final class AuthenticateResponse extends AbstractResponse implements InitializationInterface {
27
    /**
28
     * @var string transaction identifier
29
     */
30
    private $id = '';
31
32
    /**
33
     * @var bool request processing result
34
     */
35
    private $success = false;
36
37
    /**
38
     * @var null|CardResponse instance with safely card data
39
     */
40
    private $Card = null;
41
42
    /**
43
     * @var string card's permanent token
44
     */
45
    private $permanentToken = '';
46
47
    /**
48
     * @var null|RecurringResponse instance with recurring payments data
49
     */
50
    private $Recurring = null;
51
52
    /**
53
     * @return string transaction identifier
54
     */
55 1
    public function getId() {
56 1
        return $this->id;
57
    }
58
59
    /**
60
     * @return boolean request processing result
61
     */
62 1
    public function isSuccess() {
63 1
        return $this->success;
64
    }
65
66
    /**
67
     * @return null|CardResponse instance with safely card data
68
     */
69 1
    public function getCard() {
70 1
        return $this->Card;
71
    }
72
73
    /**
74
     * @return string card's permanent token
75
     */
76 1
    public function getPermanentToken() {
77 1
        return $this->permanentToken;
78
    }
79
80
    /**
81
     * @return null|RecurringResponse instance with recurring payments data
82
     */
83 1
    public function getRecurring() {
84 1
        return $this->Recurring;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     * @return AuthenticateResponse instance, that describes card authentication data
90
     */
91 1
    public static function initializeByString($string) {
92 1
        $Response        = json_decode($string);
93 1
        $Result          = new AuthenticateResponse();
94 1
        $Result->id      = $Response->id;
95 1
        $Result->success = (bool) $Response->success;
96 1
        $Result->Card    = CardResponse::initializeByObject($Response->card);
97 1
        if (isset($Response->permanentToken)) {
98 1
            $Result->permanentToken = (string) $Response->permanentToken;
99 1
        }
100 1
        if (isset($Response->recurring)) {
101 1
            $Result->Recurring = RecurringResponse::initializeByObject($Response->recurring);
102 1
        }
103 1
        return $Result;
104
    }
105
106
    /**
107
     * @inheritdoc
108
     */
109 1
    public function __toString() {
110
        $format = <<<'EOD'
111
authenticate result
112
    id:             %s
113
    success:        %s
114
    permanentToken: %s
115
    card
116
%s
117
    recurring
118
%s
119 1
EOD;
120 1
        return sprintf($format
121 1
            , $this->getId()
122 1
            , json_encode($this->isSuccess())
123 1
            , $this->getPermanentToken()
124 1
            , (string) $this->getCard()
125 1
            , (string) $this->getRecurring());
126
    }
127
}
128