Test Setup Failed
Push — master ( a9e404...0579c6 )
by Alex
03:26
created

CallbackRequest::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nxmad\Larapay\Requests;
6
7
use Nxmad\Larapay\Abstracts\Gateway;
8
use Nxmad\Larapay\Abstracts\Request;
9
use Illuminate\Http\Request as HttpRequest;
10
use Nxmad\Larapay\Exceptions\SignatureValidateException;
11
12
class CallbackRequest extends Request
13
{
14
    /**
15
     * CallbackRequest constructor.
16
     *
17
     * @param Gateway $gateway
18
     * @param HttpRequest $request
19
     *
20
     * @throws SignatureValidateException
21
     */
22
    public function __construct(Gateway $gateway, HttpRequest $request)
23
    {
24
        parent::__construct($gateway, $request);
25
26
        if (! $this->validate()) {
27
            throw new SignatureValidateException;
28
        }
29
    }
30
31
    /**
32
     * @return bool
33
     */
34
    protected function validate(): bool
35
    {
36
        return $this->get(self::SIGNATURE) === $this->gateway->sign($this);
37
    }
38
}
39