Sl   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 4
c 6
b 0
f 1
lcom 1
cbo 7
dl 0
loc 66
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A httpClient() 0 8 2
A searchStation() 0 6 1
A departuresFrom() 0 6 1
1
<?php
2
3
namespace Sl;
4
5
use Sl\Mappers\StationMapper;
6
use Sl\Mappers\DepartureMapper;
7
use Sl\Collections\StationCollection;
8
use Sl\Collections\DepartureCollection;
9
use Sl\Contracts\PublicTransportSystemInterface;
10
use Sl\Contracts\Foundation\StationInterface;
11
12
class Sl implements PublicTransportSystemInterface
13
{
14
    /**
15
     * Sl Http API base uri.
16
     */
17
    const BASE_URI = 'http://sl.se/api/';
18
19
    /**
20
     * Search station API uri.
21
     */
22
    const SEARCH_STATION_URI = 'TypeAhead/Find/';
23
24
    /**
25
     * Departures API uri.
26
     */
27
    const DEPARTURES_FROM_URI = 'sv/RealTime/GetDepartures/';
28
29
    /**
30
     * Http client instance.
31
     *
32
     * @var \Sl\Contracts\HttpClientInterface
33
     */
34
    private $httpClient;
35
36
    /**
37
     * Get Http client instance.
38
     *
39
     * @return \Sl\Contracts\HttpClientInterface
40
     */
41 2
    public function httpClient()
42
    {
43 2
        if ($this->httpClient === null) {
44 2
            $this->httpClient = new HttpClient(self::BASE_URI);
45 2
        }
46
47 2
        return $this->httpClient;
48
    }
49
50
    /**
51
     * Search for station.
52
     *
53
     * @param string $query
54
     *
55
     * @return \Sl\Contracts\Collections\StationCollectionInterface
56
     */
57 1
    public function searchStation($query)
58
    {
59 1
        $data = $this->httpClient()->getAndParseJson(self::SEARCH_STATION_URI.$query);
60
61 1
        return StationCollection::fromArray($data, new StationMapper());
62
    }
63
64
    /**
65
     * Get departures from station.
66
     *
67
     * @param \Sl\Contracts\Foundation\StationInterface $station
68
     *
69
     * @return \Sl\Contracts\Collections\DepartureCollectionInterface
70
     */
71 1
    public function departuresFrom(StationInterface $station)
72
    {
73 1
        $data = $this->httpClient()->getAndParseJson(self::DEPARTURES_FROM_URI.$station->id());
74
75 1
        return DepartureCollection::fromArray($data, new DepartureMapper());
76
    }
77
}
78