Completed
Push — master ( 346425...6beaf7 )
by Jan Philip
05:33
created

NetworkService::getWeekWithLocation()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 5
nop 2
crap 2
1
<?php
2
/**
3
 * Created by IntelliJ IDEA.
4
 * User: uni
5
 * Date: 22.11.17
6
 * Time: 19:13
7
 */
8
9
namespace JPBernius\FMeat\Services;
10
11
12
use GuzzleHttp\Client as HttpClient;
13
use GuzzleHttp\Exception\RequestException;
14
use JPBernius\FMeat\Entities\{
15
    CalendarWeek,
16
    Week
17
};
18
use JPBernius\FMeat\Exeptions\NetworkingException;
19
use JPBernius\FMeat\Utilities\UrlBuilder;
20
21
/**
22
 * Class NetworkService
23
 * @package JPBernius\FMeat\Services
24
 */
25
class NetworkService
26
{
27
28
    /** @var HttpClient */
29
    private $httpClient;
30
31
    /** @var UrlBuilder */
32
    private $urlBuilder;
33
34
    /**
35
     * NetworkService constructor.
36
     * @param HttpClient $httpClient
37
     * @param UrlBuilder $urlBuilder
38
     */
39 6
    public function __construct(HttpClient $httpClient, UrlBuilder $urlBuilder)
40
    {
41 6
        $this->httpClient = $httpClient;
42 6
        $this->urlBuilder = $urlBuilder;
43 6
    }
44
45
    /**
46
     * @param int $week
0 ignored issues
show
Bug introduced by
There is no parameter named $week. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
47
     * @param int $year
0 ignored issues
show
Bug introduced by
There is no parameter named $year. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
48
     * @param string $location
49
     * @return Week
50
     * @throws NetworkingException
51
     */
52 6
    public function getWeekWithLocation(CalendarWeek $calendarWeek, string $location): Week
53
    {
54 6
        $url = $this->urlBuilder->getUrlForLocationYearWeek($location, $calendarWeek);
55
        try {
56 6
            $response = $this->httpClient->get($url);
57 3
            $jsonResponse = (string)$response->getBody();
58 3
            $jsonObject = json_decode($jsonResponse);
59
60 3
            return Week::fromJson($jsonObject);
61 3
        } catch (RequestException $requestException) {
62 3
            throw new NetworkingException();
63
        }
64
    }
65
66
}