NetlifyBuildHook::trigger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Developmint\NetlifyBuildHook;
4
5
use GuzzleHttp\Client;
6
7
class NetlifyBuildHook
8
{
9
    /** @var \GuzzleHttp\Client */
10
    protected $client;
11
    protected $id;
12
    protected $branch;
13
    protected $title;
14
    const BASE_URL = 'https://api.netlify.com/build_hooks/';
15
16
    /**
17
     * @param \GuzzleHttp\Client $client HTTP Client that'll trigger the hook
18
     * @param string $id string Hook identifier
19
     * @param string? $branch The branch that should be used for the build
0 ignored issues
show
Documentation Bug introduced by
The doc comment string? at position 0 could not be parsed: Unknown type name 'string?' at position 0 in string?.
Loading history...
20
     * @param string? $title The title for the deploy message on Netlify
21
     */
22
    public function __construct(Client $client, string $id, $title = null, $branch = null)
23
    {
24
        $this->client = $client;
25
        $this->id = $id;
26
        $this->title = $title;
27
        $this->branch = $branch;
28
    }
29
30
    public function trigger() : void
31
    {
32
        $this->client->post(self::BASE_URL . $this->id, [
33
            "query" => [
34
                'trigger_branch' => $this->branch,
35
                'trigger_title' => $this->title
36
            ]
37
        ]);
38
    }
39
}