CallbackRequest::validate()   A
last analyzed

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 Nxmad\Larapay\Exceptions\SignatureValidateException;
10
11
class CallbackRequest extends Request
12
{
13
    /**
14
     * CallbackRequest constructor.
15
     *
16
     * @param Gateway $gateway
17
     * @param array $data
18
     *
19
     * @throws SignatureValidateException
20
     */
21
    public function __construct(Gateway $gateway, $data = [])
22
    {
23
        parent::__construct($gateway, $data);
24
25
        if (! $this->validate()) {
26
            throw new SignatureValidateException;
27
        }
28
    }
29
30
    /**
31
     * @return bool
32
     */
33
    protected function validate(): bool
34
    {
35
        return $this->get(self::SIGNATURE) === $this->sign();
36
    }
37
}
38