Completed
Push — master ( a7df58...69cda4 )
by Toan
16s
created

TransitionResponse::renderListTransitions()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 32
Code Lines 21

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 6
nop 0
dl 32
loc 32
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright © 2017 Toan Nguyen. All rights reserved.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Gojira\Jira\Response;
10
11
use Gojira\Api\Response\BaseResponse;
12
use Gojira\Api\Response\ResponseInterface;
13
use Symfony\Component\Console\Helper\TableCell;
14
15
/**
16
 * Render result for JIRA REST /transitions
17
 *
18
 * @package Gojira\Jira\Response
19
 * @author  Toan Nguyen <[email protected]>
20
 */
21 View Code Duplication
class TransitionResponse extends IssueResponse implements ResponseInterface
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function render($type = null)
27
    {
28
        switch ($type) {
29
            case 'issue:transit:get':
30
                $result = $this->renderListTransitions();
31
                break;
32
            case 'issue:transit:start':
33
            case 'issue:transit:stop':
34
            case 'issue:transit:review':
35
            case 'issue:transit:done':
36
                $result = $this->renderDoTransition();
37
                break;
38
            default:
39
                $result = $this->renderNothing();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->renderNothing() (which targets Gojira\Api\Response\BaseResponse::renderNothing()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
                break;
41
        }
42
43
        return $result;
44
    }
45
46
    /**
47
     * Returns list of worklogs in a JIRA ticket
48
     * - Command: worklog:show (['worklog', 'wlog:s'])
49
     *
50
     * @return array
51
     */
52
    protected function renderListTransitions()
53
    {
54
        $rows = [];
55
56
        if ($this->response[self::TOTAL] === 0) {
57
            $rows[] = [new TableCell('No work yet logged.', ['colspan' => 5])];
58
        }
59
60
        $transitions = $this->response[self::TRANSITIONS];
61
        $totalTransitions = count($transitions);
62
        for ($counter = 0; $counter < $totalTransitions; $counter++) {
63
            $transitionId = $transitions[$counter][self::ID];
64
            $transitionName = $transitions[$counter][self::NAME];
65
            $author = $transitions[$counter][self::AUTHOR][self::DISPLAY_NAME];
66
            $timeSpent = $transitions[$counter][self::TIME_SPENT];
67
            $comment = $transitions[$counter][self::COMMENT];
68
69
            if (strlen($comment) > 50) {
70
                $comment = substr($comment, 0, 47) . '...';
71
            }
72
73
            $rows[] = [
74
                $transitionId,
75
                $transitionName,
76
                $author,
77
                $timeSpent,
78
                $comment
79
            ];
80
        }
81
82
        return $rows;
83
    }
84
85
    /**
86
     * Returns worklog data after added/updated in a JIRA ticket
87
     * - Command: worklog:add (['worklogadd', 'wlog:a'])
88
     * - Command: worklog:update (['worklogupdate', 'wlog:u'])
89
     *
90
     * @return array
91
     */
92
    protected function renderDoTransition()
93
    {
94
        $rows = [];
95
        $worklogId = $this->response[self::ID];
96
        $startDate = $this->response[self::CREATED];
97
        $author = $this->response[self::AUTHOR][self::DISPLAY_NAME];
98
        $timeSpent = $this->response[self::TIME_SPENT];
99
        $comment = $this->response[self::COMMENT];
100
101
        if (strlen($comment) > 50) {
102
            $comment = substr($comment, 0, 47) . '...';
103
        }
104
105
        $rows[] = [
106
            $worklogId,
107
            $startDate,
108
            $author,
109
            $timeSpent,
110
            $comment
111
        ];
112
113
        return $rows;
114
    }
115
}
116