Topic::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
use Freshdesk\Resources\Traits\DeleteTrait;
11
use Freshdesk\Resources\Traits\MonitorTrait;
12
use Freshdesk\Resources\Traits\UpdateTrait;
13
use Freshdesk\Resources\Traits\ViewTrait;
14
15
/**
16
 *
17
 * Topic Resource
18
 *
19
 * Provides access to topic resources
20
 *
21
 * @package Api\Resources
22
 */
23 View Code Duplication
class Topic 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...
24
{
25
26
    use ViewTrait, UpdateTrait, DeleteTrait, MonitorTrait;
27
28
    /**
29
     * The topic resource endpoint
30
     *
31
     * @var string
32
     * @internal
33
     */
34
    protected $endpoint = '/discussions/topics';
35
36
    /**
37
     * The forums resource endpoint
38
     *
39
     * @var string
40
     * @internal
41
     */
42
    private $forumsEndpoint = '/discussions/forums';
43
44
    /**
45
     * Creates the forums endpoint
46
     * @param string $id
47
     * @return string
48
     * @internal
49
     */
50
    protected function forumsEndpoint($id = null)
51
    {
52
        return $id === null ? $this->forumsEndpoint : $this->forumsEndpoint . '/' . $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->forumsEndpoint($id . '/topics'), $data);
77
    }
78
79
    /**
80
     *
81
     * List topics in a forum
82
     *
83
     * @api
84
     * @param int $id
85
     * @param array|null $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->forumsEndpoint($id . '/topics'), null, $query);
101
    }
102
103
}
104