Current   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 9 1
A __construct() 0 3 1
1
<?php
2
3
namespace Shobi\Weatherapp\Endpoints;
4
5
use Shobi\Weatherapp\Http\Client;
6
use Shobi\Weatherapp\Weather\Weather;
7
use Shobi\Weatherapp\Contracts\Endpoint;
8
9
class Current implements Endpoint
10
{
11
    const ENDPOINT = 'weather';
12
13
    private $client;
14
15
    /**
16
     * Current constructor.
17
     * @param Client $client
18
     */
19
    public function __construct(Client $client)
20
    {
21
        $this->client = $client;
22
    }
23
24
    /**
25
     * @param string $location
26
     * @return Shobi\Weatherapp\Weather\Weather
0 ignored issues
show
Bug introduced by
The type Shobi\Weatherapp\Endpoin...therapp\Weather\Weather was not found. Did you mean Shobi\Weatherapp\Weather\Weather? If so, make sure to prefix the type with \.
Loading history...
27
     *
28
     * @throws GuzzleHttp\Exception\ClientException\ClientException
29
     * fetches the current weather data from the api
30
     */
31
    public function get($location = "london") : Weather
32
    {
33
        $reponse  = json_decode($this->client->get(self::ENDPOINT, ['q' => $location]), true);
34
                
35
        $description = $reponse['weather'][0]['description'];
36
        $temparature = $reponse['main']['temp'];
37
        $location    = $reponse['name'];
38
39
        return new Weather($description, $temparature, $location);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Shobi\Weather...temparature, $location) returns the type Shobi\Weatherapp\Weather\Weather which is incompatible with the documented return type Shobi\Weatherapp\Endpoin...therapp\Weather\Weather.
Loading history...
40
    }
41
}