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

Comment::topicsEndpoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
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