Form::initable()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 3
nc 5
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 5
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Loevgaard\AltaPay\Callback;
4
5
use Loevgaard\AltaPay;
6
use Money\Money;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
class Form extends Callback
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $shopOrderId;
15
16
    /**
17
     * @var Money
18
     */
19
    protected $amount;
20
21
    /**
22
     * ISO 4217 currency code
23
     *
24
     * @var int
25
     */
26
    protected $currency;
27
28
    /**
29
     * ISO 639 alpha 2 language code
30
     *
31
     * @var string
32
     */
33
    protected $language;
34
35
    /**
36
     * @var boolean
37
     */
38
    protected $embeddedWindow;
39
40 6
    public function init()
41
    {
42 6
        $currency = (int)$this->body['currency'];
43 6
        $alphaCurrency = AltaPay\alphaCurrencyFromNumeric($currency);
44
45 6
        $this->shopOrderId = $this->body['shop_orderid'];
46 6
        $this->amount = AltaPay\createMoneyFromFloat($alphaCurrency, (float)$this->body['amount']);
47 6
        $this->currency = $currency;
48 6
        $this->language = $this->body['language'];
49 6
        $this->embeddedWindow = (int)($this->body['embedded_window'] === 1);
0 ignored issues
show
Documentation Bug introduced by
The property $embeddedWindow was declared of type boolean, but (int) ($this->body['embedded_window'] === 1) is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
50 6
    }
51
52 15
    public static function initable(ServerRequestInterface $request): bool
53
    {
54 15
        $body = static::getBodyFromRequest($request);
55
56 15
        return isset($body['shop_orderid']) && isset($body['amount']) && isset($body['currency']) && isset($body['language']) && isset($body['embedded_window']);
57
    }
58
59
    /**
60
     * @return string
61
     */
62 3
    public function getShopOrderId(): string
63
    {
64 3
        return $this->shopOrderId;
65
    }
66
67
    /**
68
     * @return Money
69
     */
70 3
    public function getAmount(): Money
71
    {
72 3
        return $this->amount;
73
    }
74
75
    /**
76
     * @return int
77
     */
78 3
    public function getCurrency(): int
79
    {
80 3
        return $this->currency;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 3
    public function getLanguage(): string
87
    {
88 3
        return $this->language;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94 3
    public function isEmbeddedWindow(): bool
95
    {
96 3
        return $this->embeddedWindow;
97
    }
98
}
99