Webhook   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 3 1
A setUrl() 0 4 1
A setActions() 0 4 1
A schema() 0 8 1
A setDescription() 0 4 1
A getActions() 0 3 1
A getHttpMethod() 0 3 1
A setHttpMethod() 0 4 1
A getDescription() 0 3 1
A actions() 0 9 3
1
<?php
2
3
namespace Ipag\Sdk\Model;
4
5
use Ipag\Sdk\Model\Schema\Mutator;
6
use Ipag\Sdk\Model\Schema\Schema;
7
use Ipag\Sdk\Model\Schema\SchemaBuilder;
8
use Kubinyete\Assertation\Assert;
9
10
/**
11
 * Webhook Class
12
 *
13
 * Classe responsável por representar o recurso Webhook.
14
 *
15
 */
16
final class Webhook extends Model
17
{
18
    public function schema(SchemaBuilder $schema): Schema
19
    {
20
        $schema->enum('http_method', ['POST', 'PUT'])->nullable();
21
        $schema->string('url')->nullable();
22
        $schema->string('description')->nullable();
23
        $schema->any('actions')->nullable();
24
25
        return $schema->build();
26
    }
27
28
    protected function actions(): Mutator
29
    {
30
        return new Mutator(
31
            null,
32
            fn($value, $ctx) =>
33
            is_null($value) ? $value :
34
            (
35
                Assert::value($value)->array() ? $value :
36
                $ctx->raise('inválido (informe um array de actions de webhook)')
37
            )
38
        );
39
    }
40
41
    public function getHttpMethod(): ?string
42
    {
43
        return $this->get('http_method');
44
    }
45
46
    public function setHttpMethod(?string $httpMethod = null): self
47
    {
48
        $this->set('http_method', $httpMethod);
49
        return $this;
50
    }
51
52
    public function getUrl(): ?string
53
    {
54
        return $this->get('url');
55
    }
56
57
    public function setUrl(?string $url = null): self
58
    {
59
        $this->set('url', $url);
60
        return $this;
61
    }
62
63
    public function getDescription(): ?string
64
    {
65
        return $this->get('description');
66
    }
67
68
    public function setDescription(?string $description = null): self
69
    {
70
        $this->set('description', $description);
71
        return $this;
72
    }
73
74
    public function getActions(): ?array
75
    {
76
        return $this->get('actions');
77
    }
78
79
    public function setActions(?array $actions = null): self
80
    {
81
        $this->set('actions', $actions);
82
        return $this;
83
    }
84
85
}