Application   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 10.1 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 10
loc 99
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getBridgeIds() 0 4 1
A getChannelIds() 0 4 1
A getDeviceNames() 0 4 1
A getEndpointIds() 0 4 1
A getName() 0 4 1
A onApplicationReplaced() 0 4 1
A onceApplicationReplaced() 0 4 1
A __construct() 10 10 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
/*
4
 * Copyright 2014 Brian Smith <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace phparia\Resources;
20
21
use phparia\Client\AriClient;
22
use phparia\Events\Event;
23
24
/**
25
 * Details of a Stasis application
26
 *
27
 * @author Brian Smith <[email protected]>
28
 */
29
class Application extends Resource
30
{
31
    /**
32
     * @var array Id's for bridges subscribed to.
33
     */
34
    private $bridgeIds;
35
36
    /**
37
     * @var array Id's for channels subscribed to.
38
     */
39
    private $channelIds;
40
41
    /**
42
     * @var array Names of the devices subscribed to.
43
     */
44
    private $deviceNames;
45
46
    /**
47
     * @var array {tech}/{resource} for endpoints subscribed to.
48
     */
49
    private $endpointIds;
50
51
    /**
52
     * @var string Name of this application
53
     */
54
    private $name;
55
56
    /**
57
     * @return array Id's for bridges subscribed to.
58
     */
59
    public function getBridgeIds()
60
    {
61
        return $this->bridgeIds;
62
    }
63
64
    /**
65
     * @return array Id's for channels subscribed to.
66
     */
67
    public function getChannelIds()
68
    {
69
        return $this->channelIds;
70
    }
71
72
    /**
73
     * @return array Names of the devices subscribed to.
74
     */
75
    public function getDeviceNames()
76
    {
77
        return $this->deviceNames;
78
    }
79
80
    /**
81
     * @return array {tech}/{resource} for endpoints subscribed to.
82
     */
83
    public function getEndpointIds()
84
    {
85
        return $this->endpointIds;
86
    }
87
88
    /**
89
     * @return string string Name of this application
90
     */
91
    public function getName()
92
    {
93
        return $this->name;
94
    }
95
96
    /**
97
     * @param callable $callback
98
     */
99
    public function onApplicationReplaced(callable $callback)
100
    {
101
        $this->on(Event::APPLICATION_REPLACED.'_'.$this->getName(), $callback);
102
    }
103
104
    /**
105
     * @param callable $callback
106
     */
107
    public function onceApplicationReplaced(callable $callback)
108
    {
109
        $this->once(Event::APPLICATION_REPLACED.'_'.$this->getName(), $callback);
110
    }
111
112
    /**
113
     * @param AriClient $client
114
     * @param string $response
115
     */
116 View Code Duplication
    public function __construct(AriClient $client, $response)
117
    {
118
        parent::__construct($client, $response);
119
120
        $this->bridgeIds = $this->getResponseValue('bridge_ids');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getResponseValue('bridge_ids') of type * is incompatible with the declared type array of property $bridgeIds.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
121
        $this->channelIds = $this->getResponseValue('channel_ids');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getResponseValue('channel_ids') of type * is incompatible with the declared type array of property $channelIds.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
122
        $this->deviceNames = $this->getResponseValue('device_names');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getResponseValue('device_names') of type * is incompatible with the declared type array of property $deviceNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
123
        $this->endpointIds = $this->getResponseValue('endpoint_ids');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getResponseValue('endpoint_ids') of type * is incompatible with the declared type array of property $endpointIds.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
124
        $this->name = $this->getResponseValue('name');
125
    }
126
127
}
128