Completed
Push — master ( 6a21b5...b393f5 )
by Matthew
02:21
created

Comment   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A topicsEndpoint() 4 4 2
A create() 4 4 1
A all() 4 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
 * @internal
19
 * @package Freshdesk\Resources
20
 */
21 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...
22
{
23
24
    use ViewTrait, UpdateTrait, DeleteTrait;
25
26
    /**
27
     * The topic resource endpoint
28
     *
29
     * @var string
30
     */
31
    protected $endpoint ='/discussions/comments' ;
32
33
    /**
34
     * The forums resource endpoint
35
     *
36
     * @var string
37
     */
38
    private $topicsEndpoint = '/discussions/topics';
39
40
    /**
41
     * Creates the forums endpoint
42
     * @param null $id
43
     * @return string
44
     */
45
    protected function topicsEndpoint($id = null)
46
    {
47
        return $id == null ? $this->topicsEndpoint : $this->topicsEndpoint . '/' . $id;
48
    }
49
50
    /**
51
     *
52
     * Create a topic for a forum
53
     *
54
     * @param int $id
55
     * @param array $data
56
     * @return array|null
57
     * @throws \Freshdesk\Exceptions\AccessDeniedException
58
     * @throws \Freshdesk\Exceptions\ApiException
59
     * @throws \Freshdesk\Exceptions\AuthenticationException
60
     * @throws \Freshdesk\Exceptions\ConflictingStateException
61
     * @throws \Freshdesk\Exceptions\NotFoundException
62
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
63
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
64
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
65
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
66
     * @throws \Freshdesk\Exceptions\ValidationException
67
     */
68
    public function create($id, array $data)
69
    {
70
        return $this->api()->request('POST', $this->topicsEndpoint($id . '/topics'), $data);
71
    }
72
73
    /**
74
     *
75
     * List comments in a topic
76
     *
77
     * @param int $id
78
     * @param array $query
79
     * @return array|null
80
     * @throws \Freshdesk\Exceptions\AccessDeniedException
81
     * @throws \Freshdesk\Exceptions\ApiException
82
     * @throws \Freshdesk\Exceptions\AuthenticationException
83
     * @throws \Freshdesk\Exceptions\ConflictingStateException
84
     * @throws \Freshdesk\Exceptions\NotFoundException
85
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
86
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
87
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
88
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
89
     * @throws \Freshdesk\Exceptions\ValidationException
90
     */
91
    public function all($id, array $query = null)
92
    {
93
        return $this->api()->request('GET', $this->topicsEndpoint($id . '/comments'), null, $query);
94
    }
95
}
96