Completed
Push — master ( 9bd30f...12e0e7 )
by KwangSeob
19s queued 12s
created

ComponentService::delete()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 8
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 16
rs 9.6111
1
<?php
2
3
namespace JiraRestApi\Component;
4
5
use JiraRestApi\JiraException;
6
use JiraRestApi\Project\Component;
7
8
class ComponentService extends \JiraRestApi\JiraClient
9
{
10
    private $uri = '/component';
11
12
    /**
13
     * Function to create a new compoonent.
14
     *
15
     * @param Component|array $component
16
     *
17
     * @throws \JiraRestApi\JiraException
18
     * @throws \JsonMapper_Exception
19
     *
20
     * @return Component class
21
     */
22
    public function create($component)
23
    {
24
        $data = json_encode($component);
25
26
        $this->log->info("Create Component=\n".$data);
27
28
        $ret = $this->exec($this->uri, $data, 'POST');
29
30
        return $this->json_mapper->map(
31
            json_decode($ret),
32
            new Component()
33
        );
34
    }
35
36
    /**
37
     * get component.
38
     *
39
     * @param $id component id
40
     *
41
     * @return Component
42
     */
43
    public function get($id)
44
    {
45
        $ret = $this->exec($this->uri.'/'.$id);
46
47
        $this->log->info('Result='.$ret);
48
49
        return $this->json_mapper->map(
50
            json_decode($ret),
51
            new Component()
52
        );
53
    }
54
55
    /**
56
     * @param Component $component
57
     *
58
     * @throws JiraException
59
     *
60
     * @return Component
61
     */
62
    public function update(Component $component)
63
    {
64
        if (!$component->id || !is_numeric($component->id)) {
65
            throw new JiraException($component->id.' is not a valid component id.');
66
        }
67
68
        $data = json_encode($component);
69
        $ret = $this->exec($this->uri.'/'.$component->id, $data, 'PUT');
70
71
        return $this->json_mapper->map(
72
            json_decode($ret),
73
            new Component()
74
        );
75
    }
76
77
    /**
78
     * @param Component       $component
79
     * @param Component|false $moveIssuesTo
80
     *
81
     * @throws JiraException
82
     *
83
     * @return bool
84
     */
85
    public function delete(Component $component, $moveIssuesTo = false)
86
    {
87
        if (!$component->id || !is_numeric($component->id)) {
88
            throw new JiraException($component->id.' is not a valid component id.');
89
        }
90
91
        $data = [];
92
        $paramArray = [];
93
94
        if ($moveIssuesTo && $moveIssuesTo instanceof Component) {
95
            $paramArray['moveIssuesTo'] = $moveIssuesTo->id;
96
        }
97
98
        $ret = $this->exec($this->uri.'/'.$component->id.$this->toHttpQueryParameter($paramArray), json_encode($data), 'DELETE');
99
100
        return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type string which is incompatible with the documented return type boolean.
Loading history...
101
    }
102
}
103