BusClient   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 127
Duplicated Lines 18.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 24
loc 127
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteLines() 0 8 1
A getCalendar() 0 8 1
A getListLines() 8 8 1
A getGroups() 0 4 1
A getTimesLines() 8 8 1
A getTimeTableLines() 8 8 1
A getNodesLines() 0 7 1
A callBusService() 0 5 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
namespace Afonso\Emt;
4
5
use DateTime;
6
use RuntimeException;
7
8
/**
9
 * The SDK client for the EMT OpenData API BUS service.
10
 *
11
 * @author Carlos Afonso Pérez <[email protected]>
12
 */
13
class BusClient extends Client
14
{
15
    /**
16
     * Return the itinerary of one or more lines.
17
     *
18
     * @param int[] $lines
19
     * @param \DateTime $date
20
     * @return \stdClass
21
     * @throws \RuntimeException
22
     */
23 3
    public function getRouteLines(array $lines, DateTime $date)
24
    {
25
        $params = [
26 3
            'Lines' => join('|', $lines),
27 3
            'SelectDate' => $date->format('d/m/Y'),
28 1
        ];
29 3
        return $this->callBusService('GetRouteLines.php', $params);
30
    }
31
32
    /**
33
     * Return calendar details for the given date interval.
34
     *
35
     * @param \DateTime $startDate
36
     * @param \DateTime $endDate
37
     * @return \stdClass
38
     * @throws \RuntimeException
39
     */
40 3
    public function getCalendar(DateTime $startDate, DateTime $endDate)
41
    {
42
        $params = [
43 3
            'SelectDateBegin' => $startDate->format('d/m/Y'),
44 3
            'SelectDateEnd' => $endDate->format('d/m/Y'),
45 1
        ];
46 3
        return $this->callBusService('GetCalendar.php', $params);
47
    }
48
49
    /**
50
     * Return a list with line details.
51
     *
52
     * @param int[] $lines
53
     * @param \DateTime $date
54
     * @return \stdClass
55
     * @throws \RuntimeException
56
     */
57 3 View Code Duplication
    public function getListLines(array $lines, DateTime $date)
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...
58
    {
59
        $params = [
60 3
            'Lines' => join('|', $lines),
61 3
            'SelectDate' => $date->format('d/m/Y'),
62 1
        ];
63 3
        return $this->callBusService('GetListLines.php', $params);
64
    }
65
66
    /**
67
     * Return details about all line groups.
68
     *
69
     * @return \stdClass
70
     * @throws \RuntimeException
71
     */
72 3
    public function getGroups()
73
    {
74 3
        return $this->callBusService('GetGroups.php');
75
    }
76
77
    /**
78
     * Return start and end operation times of one or more lines.
79
     *
80
     * @param int[] $lines
81
     * @param \DateTime $date
82
     * @return \stdClass
83
     * @throws \RuntimeException
84
     */
85 3 View Code Duplication
    public function getTimesLines(array $lines, DateTime $date)
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...
86
    {
87
        $params = [
88 3
            'Lines' => join('|', $lines),
89 3
            'SelectDate' => $date->format('d/m/Y'),
90 1
        ];
91 3
        return $this->callBusService('GetTimesLines.php', $params);
92
    }
93
94
    /**
95
     * Return timetable details of one or more lines.
96
     *
97
     * @param int[] $lines
98
     * @param \DateTime $date
99
     * @return \stdClass
100
     * @throws \RuntimeException
101
     */
102 3 View Code Duplication
    public function getTimeTableLines(array $lines, DateTime $date)
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...
103
    {
104
        $params = [
105 3
            'Lines' => join('|', $lines),
106 3
            'SelectDate' => $date->format('d/m/Y'),
107 1
        ];
108 3
        return $this->callBusService('GetTimeTableLines.php', $params);
109
    }
110
111
    /**
112
     * Return details of one or more bus stops including name, served lines
113
     * and geographic coordinates.
114
     *
115
     * @param int[] $stopIds
116
     * @return \stdClass
117
     * @throws \RuntimeException
118
     */
119 3
    public function getNodesLines(array $stopIds)
120
    {
121
        $params = [
122 3
            'Nodes' => join('|', $stopIds),
123 1
        ];
124 3
        return $this->callBusService('GetNodesLines.php', $params);
125
    }
126
127
    /**
128
     * Make an arbitrary call to the BUS service.
129
     *
130
     * @param string $endpoint
131
     * @param array $params
132
     * @return \stdClass
133
     */
134 21
    protected function callBusService($endpoint, array $params = [])
135
    {
136 21
        $url = self::ENDPOINT . '/emt-proxy-server/last/bus/' . $endpoint;
137 21
        return $this->launcher->launchRequest($url, $params)->resultValues;
138
    }
139
}
140