Passed
Push — master ( f3637e...ec11f6 )
by Gabriel
01:55
created

Ticket::createTicket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 14
nc 1
nop 2
dl 0
loc 24
rs 9.7998
c 1
b 0
f 1
1
<?php
2
3
namespace codingFive0\octadesk;
4
5
class Ticket extends Octadesk
6
{
7
8
    public function __construct($accToken)
9
    {
10
        $this->setAccesToken($accToken);
11
        parent::__construct();
12
    }
13
14
    public function customList()
15
    {
16
        $this->request(
17
            "GET",
18
            "tickets/custom-lists"
19
        );
20
21
        return $this;
22
    }
23
24
    public function defaultList()
25
    {
26
        $this->request(
27
            "GET",
28
            "tickets/default-lists"
29
        );
30
31
        return $this;
32
    }
33
34
    public function findByRequesterId($idRequester, $lastNumber = null)
35
    {
36
        $params["idRequester"] = $idRequester;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.
Loading history...
37
38
        if ($lastNumber) {
39
            $params["lastNumber"] = $lastNumber;
40
        }
41
42
        $this->request(
43
            "GET",
44
            "tickets",
45
            $params
46
        );
47
48
        return $this;
49
    }
50
51
    public function findByNumber($number)
52
    {
53
        $this->request(
54
            "GET",
55
            "tickets/{$number}"
56
        );
57
58
        return $this;
59
    }
60
61
    public function createTicket(array $ticket, array $customField = [])
62
    {
63
        ;
64
        $this->request(
65
            "POST",
66
            "tickets",
67
            [
68
                "requester" => [
69
                    "email" => ($ticket["requester_email"]),
70
                    "name" => ($ticket["requester_name"])
71
                ],
72
                "summary" => ($ticket["summary"] ?? null),
73
                "comments" => [
74
                    "description" => [
75
                        "content" => ($ticket["comments_content"] ?? null)
76
                    ]
77
                ],
78
                "customField" => $customField
79
            ],
80
            null,
81
            true
82
        );
83
84
        return $this;
85
    }
86
}