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

MonitorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 93
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 24
loc 93
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
endpoint() 0 1 ?
api() 0 1 ?
A monitor() 8 8 1
A unmonitor() 8 8 1
A monitorStatus() 8 8 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: Matthew
5
 * Date: 21/04/2016
6
 * Time: 10:23 AM
7
 */
8
9
namespace Freshdesk\Resources\Traits;
10
11
trait MonitorTrait
12
{
13
14
    /**
15
     * @param null $end string
16
     * @return string
17
     */
18
    abstract protected function endpoint($end = null);
19
20
    /**
21
     * @return \Freshdesk\Api
22
     */
23
    abstract protected function api();
24
25
26
    /**
27
     *
28
     * Monitor the resource for the given user
29
     *
30
     * @param int $userId
31
     * @return array|null
32
     * @throws \Freshdesk\Exceptions\AccessDeniedException
33
     * @throws \Freshdesk\Exceptions\ApiException
34
     * @throws \Freshdesk\Exceptions\AuthenticationException
35
     * @throws \Freshdesk\Exceptions\ConflictingStateException
36
     * @throws \Freshdesk\Exceptions\NotFoundException
37
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
38
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
39
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
40
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
41
     * @throws \Freshdesk\Exceptions\ValidationException
42
     */
43 View Code Duplication
    public function monitor($id, $userId)
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45
        $data = [
46
            'user_id' => $userId
47
        ];
48
49
        return $this->api()->request('POST', $this->endpoint($id . '/follow'), $data);
50
    }
51
52
    /**
53
     *
54
     * Unmonitor a resource for the given user
55
     *
56
     * @param int $userId
57
     * @return array|null
58
     * @throws \Freshdesk\Exceptions\AccessDeniedException
59
     * @throws \Freshdesk\Exceptions\ApiException
60
     * @throws \Freshdesk\Exceptions\AuthenticationException
61
     * @throws \Freshdesk\Exceptions\ConflictingStateException
62
     * @throws \Freshdesk\Exceptions\NotFoundException
63
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
64
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
65
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
66
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
67
     * @throws \Freshdesk\Exceptions\ValidationException
68
     */
69 View Code Duplication
    public function unmonitor($id, $userId)
0 ignored issues
show
Duplication introduced by
This method 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...
70
    {
71
        $query = [
72
            'user_id' => $userId
73
        ];
74
75
        return $this->api()->request('POST', $this->endpoint($id . '/follow'), null, $query);
76
    }
77
78
    /**
79
     *
80
     * UnMonitor a forum for the given user
81
     *
82
     * @param int $userId
83
     * @return array|null
84
     * @throws \Freshdesk\Exceptions\AccessDeniedException
85
     * @throws \Freshdesk\Exceptions\ApiException
86
     * @throws \Freshdesk\Exceptions\AuthenticationException
87
     * @throws \Freshdesk\Exceptions\ConflictingStateException
88
     * @throws \Freshdesk\Exceptions\NotFoundException
89
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
90
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
91
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
92
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
93
     * @throws \Freshdesk\Exceptions\ValidationException
94
     */
95 View Code Duplication
    public function monitorStatus($id, $userId)
0 ignored issues
show
Duplication introduced by
This method 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...
96
    {
97
        $query = [
98
            'user_id' => $userId
99
        ];
100
101
        return $this->api()->request('GET', $this->endpoint($id . '/follow'), null, $query);
102
    }
103
}