Passed
Pull Request — master (#346)
by
unknown
02:08
created

RequestService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 51
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addComment() 0 19 2
A __construct() 0 4 1
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
     * @return RequestComment
39
     * @throws JiraException
40
     * @throws \JsonMapper_Exception
41
     */
42
    public function addComment($issueIdOrKey, RequestComment $requestComment): RequestComment
43
    {
44
        $this->log->info("addComment=\n");
45
46
        if (empty($requestComment->body)) {
47
            throw new JiraException('comment param must be an instance of RequestComment and have body text.');
48
        }
49
50
        $data = json_encode($requestComment);
51
52
        $ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data);
53
54
        $this->log->debug('add comment result=' . var_export($ret, true));
55
        $requestComment = $this->json_mapper->map(
56
            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

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