Comment   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 92.59 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 75
loc 81
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A topicsEndpoint() 4 4 2
A create() 4 4 1
A all() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matt
5
 * Date: 20/04/2016
6
 * Time: 2:32 PM
7
 */
8
9
namespace Freshdesk\Resources;
10
11
use Freshdesk\Resources\Traits\DeleteTrait;
12
use Freshdesk\Resources\Traits\UpdateTrait;
13
use Freshdesk\Resources\Traits\ViewTrait;
14
15
/**
16
 * Comment resource
17
 *
18
 * This provides access to the comment resources
19
 *
20
 * @package Api\Resources
21
 */
22 View Code Duplication
class Comment extends AbstractResource
0 ignored issues
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...
23
{
24
25
    use ViewTrait, UpdateTrait, DeleteTrait;
26
27
    /**
28
     * The topic resource endpoint
29
     *
30
     * @var string
31
     * @internal
32
     */
33
    protected $endpoint = '/discussions/comments';
34
35
    /**
36
     * The forums resource endpoint
37
     *
38
     * @var string
39
     * @internal
40
     */
41
    private $topicsEndpoint = '/discussions/topics';
42
43
    /**
44
     * Creates the forums endpoint
45
     *
46
     * @param string $id
47
     * @return string
48
     * @internal
49
     */
50
    protected function topicsEndpoint($id = null)
51
    {
52
        return $id === null ? $this->topicsEndpoint : $this->topicsEndpoint . '/' . $id;
53
    }
54
55
    /**
56
     *
57
     * Create a topic for a forum
58
     *
59
     * @api
60
     * @param int $id
61
     * @param array $data
62
     * @return array|null
63
     * @throws \Freshdesk\Exceptions\AccessDeniedException
64
     * @throws \Freshdesk\Exceptions\ApiException
65
     * @throws \Freshdesk\Exceptions\AuthenticationException
66
     * @throws \Freshdesk\Exceptions\ConflictingStateException
67
     * @throws \Freshdesk\Exceptions\NotFoundException
68
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
69
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
70
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
71
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
72
     * @throws \Freshdesk\Exceptions\ValidationException
73
     */
74
    public function create($id, array $data)
75
    {
76
        return $this->api()->request('POST', $this->topicsEndpoint($id . '/topics'), $data);
77
    }
78
79
    /**
80
     *
81
     * List comments in a topic
82
     *
83
     * @api
84
     * @param int $id
85
     * @param array $query
86
     * @return array|null
87
     * @throws \Freshdesk\Exceptions\AccessDeniedException
88
     * @throws \Freshdesk\Exceptions\ApiException
89
     * @throws \Freshdesk\Exceptions\AuthenticationException
90
     * @throws \Freshdesk\Exceptions\ConflictingStateException
91
     * @throws \Freshdesk\Exceptions\NotFoundException
92
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
93
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
94
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
95
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
96
     * @throws \Freshdesk\Exceptions\ValidationException
97
     */
98
    public function all($id, array $query = null)
99
    {
100
        return $this->api()->request('GET', $this->topicsEndpoint($id . '/comments'), null, $query);
101
    }
102
}
103