Code Duplication    Length = 93-95 lines in 2 locations

src/Gojira/Jira/Response/TransitionResponse.php 1 location

@@ 21-115 (lines=95) @@
18
 * @package Gojira\Jira\Response
19
 * @author  Toan Nguyen <[email protected]>
20
 */
21
class TransitionResponse extends IssueResponse implements ResponseInterface
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();
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

src/Gojira/Jira/Response/WorklogResponse.php 1 location

@@ 21-113 (lines=93) @@
18
 * @package Gojira\Jira\Response
19
 * @author  Toan Nguyen <[email protected]>
20
 */
21
class WorklogResponse extends IssueResponse implements ResponseInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function render($type = null)
27
    {
28
        switch ($type) {
29
            case 'worklog:show':
30
                $result = $this->renderListWorklogs();
31
                break;
32
            case 'worklog:add':
33
            case 'worklog:update':
34
                $result = $this->renderAddUpdateWorklog();
35
                break;
36
            default:
37
                $result = $this->renderNothing();
38
                break;
39
        }
40
41
        return $result;
42
    }
43
44
    /**
45
     * Returns list of worklogs in a JIRA ticket
46
     * - Command: worklog:show (['worklog', 'wlog:s'])
47
     *
48
     * @return array
49
     */
50
    protected function renderListWorklogs()
51
    {
52
        $rows = [];
53
54
        if ($this->response[self::TOTAL] === 0) {
55
            $rows[] = [new TableCell('No work yet logged.', ['colspan' => 5])];
56
        }
57
58
        $worklogs = $this->response[self::WORKLOGS];
59
        $totalWorklogs = count($worklogs);
60
        for ($counter = 0; $counter < $totalWorklogs; $counter++) {
61
            $worklogId = $worklogs[$counter][self::ID];
62
            $startDate = $worklogs[$counter][self::CREATED];
63
            $author = $worklogs[$counter][self::AUTHOR][self::DISPLAY_NAME];
64
            $timeSpent = $worklogs[$counter][self::TIME_SPENT];
65
            $comment = $worklogs[$counter][self::COMMENT];
66
67
            if (strlen($comment) > 50) {
68
                $comment = substr($comment, 0, 47) . '...';
69
            }
70
71
            $rows[] = [
72
                $worklogId,
73
                $startDate,
74
                $author,
75
                $timeSpent,
76
                $comment
77
            ];
78
        }
79
80
        return $rows;
81
    }
82
83
    /**
84
     * Returns worklog data after added/updated in a JIRA ticket
85
     * - Command: worklog:add (['worklogadd', 'wlog:a'])
86
     * - Command: worklog:update (['worklogupdate', 'wlog:u'])
87
     *
88
     * @return array
89
     */
90
    protected function renderAddUpdateWorklog()
91
    {
92
        $rows = [];
93
        $worklogId = $this->response[self::ID];
94
        $startDate = $this->response[self::CREATED];
95
        $author = $this->response[self::AUTHOR][self::DISPLAY_NAME];
96
        $timeSpent = $this->response[self::TIME_SPENT];
97
        $comment = $this->response[self::COMMENT];
98
99
        if (strlen($comment) > 50) {
100
            $comment = substr($comment, 0, 47) . '...';
101
        }
102
103
        $rows[] = [
104
            $worklogId,
105
            $startDate,
106
            $author,
107
            $timeSpent,
108
            $comment
109
        ];
110
111
        return $rows;
112
    }
113
}
114