RecurringResponse::getFrequency()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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