RecurringResponse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 4
c 4
b 1
f 0
lcom 1
cbo 0
dl 0
loc 49
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFrequency() 0 3 1
A getEndsAt() 0 3 1
A initializeByObject() 0 6 1
A __toString() 0 9 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\ObjectInitializedInterface;
21
use DateTime;
22
use stdClass;
23
24
/**
25
 * Class for transaction recurrent data
26
 * @author alxmsl
27
 */
28
final class RecurringResponse implements ObjectInitializedInterface {
29
    /**
30
     * @var int minimal number of days between recurring payments
31
     */
32
    private $frequency = 0;
33
34
    /**
35
     * @var int last date timestamp when recurring payments will work
36
     */
37
    private $endsAt = 0;
38
39
    /**
40
     * @return int minimal number of days between recurring payments
41
     */
42 2
    public function getFrequency() {
43 2
        return $this->frequency;
44
    }
45
46
    /**
47
     * @return int last date timestamp when recurring payments will work
48
     */
49 2
    public function getEndsAt() {
50 2
        return $this->endsAt;
51
    }
52
53
    /**
54
     * @inheritdoc
55
     * @return RecurringResponse transaction recurrent data instance
56
     */
57 2
    public static function initializeByObject(stdClass $Object) {
58 2
        $Result            = new RecurringResponse();
59 2
        $Result->frequency = (int) $Object->frequency;
60 2
        $Result->endsAt    = strtotime($Object->endsAt);
61 2
        return $Result;
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 2
    public function __toString() {
68
        $format = <<<'EOD'
69
        frequency:  %s
70
        endsAt:     %s
71 2
EOD;
72 2
        return sprintf($format
73 2
            , $this->getFrequency()
74 2
            , gmdate(DateTime::ISO8601, $this->getEndsAt()));
75
    }
76
}
77