Passed
Push — master ( 9e7fa6...c5d7ac )
by KwangSeob
03:35
created

RequestService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 4
rs 10
1
<?php
2
3
namespace JiraRestApi\Request;
4
5
use JiraRestApi\Configuration\ConfigurationInterface;
6
use JiraRestApi\JiraException;
7
use JiraRestApi\ServiceDeskTrait;
8
use Psr\Log\LoggerInterface;
9
10
class RequestService extends \JiraRestApi\JiraClient
11
{
12
    use ServiceDeskTrait;
13
14
    private $uri = '/request';
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param ConfigurationInterface $configuration
20
     * @param LoggerInterface        $logger
21
     * @param string                 $path
22
     *
23
     * @throws JiraException
24
     * @throws \Exception
25
     */
26
    public function __construct(ConfigurationInterface $configuration = null, LoggerInterface $logger = null, $path = './')
27
    {
28
        parent::__construct($configuration, $logger, $path);
29
        $this->setupAPIUri();
30
    }
31
32
    /**
33
     * Add the given comment to the specified request based on the provided $issueIdOrKey value. Returns a new
34
     * RequestComment with the response.
35
     *
36
     * @param string|int     $issueIdOrKey
37
     * @param RequestComment $requestComment
38
     *
39
     * @throws JiraException
40
     * @throws \JsonMapper_Exception
41
     *
42
     * @return RequestComment
43
     */
44
    public function addComment($issueIdOrKey, RequestComment $requestComment): RequestComment
45
    {
46
        $this->log->info("addComment=\n");
47
48
        if (empty($requestComment->body)) {
49
            throw new JiraException('comment param must be an instance of RequestComment and have body text.');
50
        }
51
52
        $data = json_encode($requestComment);
53
54
        $ret = $this->exec($this->uri."/$issueIdOrKey/comment", $data);
55
56
        $this->log->debug('add comment result='.var_export($ret, true));
57
        $requestComment = $this->json_mapper->map(
58
            json_decode($ret),
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
            json_decode(/** @scrutinizer ignore-type */ $ret),
Loading history...
59
            new RequestComment()
60
        );
61
62
        return $requestComment;
63
    }
64
}
65