Completed
Pull Request — v3 (#135)
by Christian
30:58 queued 15:52
created

TestHttpClient::currentWeather()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
4
 *
5
 * @license MIT
6
 *
7
 * Please see the LICENSE file distributed with this source code for further
8
 * information regarding copyright and licensing.
9
 *
10
 * Please visit the following links to read about the usage policies and the license of
11
 * OpenWeatherMap before using this class:
12
 *
13
 * @see http://www.OpenWeatherMap.org
14
 * @see http://www.OpenWeatherMap.org/terms
15
 * @see http://openweathermap.org/appid
16
 */
17
18
namespace Cmfcmf\OpenWeatherMap\Tests;
19
20
use Psr\Http\Client\ClientInterface;
21
use Psr\Http\Message\RequestInterface;
22
use Psr\Http\Message\ResponseInterface;
23
use Http\Factory\Guzzle\ResponseFactory;
24
use GuzzleHttp\Psr7;
25
26
class TestHttpClient implements ClientInterface
27
{
28
    /**
29
     * @var ResponseFactory
30
     */
31
    private $responseFactory;
32
33
    public function __construct()
34
    {
35
        $this->responseFactory = new ResponseFactory();
36
    }
37
38
    public function sendRequest(RequestInterface $request): ResponseInterface
39
    {
40
        $url = $request->getUri();
41
        $format = strpos($url, 'json') !== false ? 'json' : 'xml';
42
        $content = "";
0 ignored issues
show
Unused Code introduced by
$content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
        if (strpos($url, 'forecast') !== false) {
44
            $content = $this->forecast($format);
45
        } elseif (strpos($url, 'group') !== false) {
46
            $content = $this->group($format);
47
        } else {
48
            $content = $this->currentWeather($format);
49
        }
50
51
        $response = $this->responseFactory->createResponse(200);
52
        return $response->withBody(Psr7\stream_for($content));
53
    }
54
55
    private function currentWeather($format)
56
    {
57
        if ($format == 'xml') {
58
            return FakeData::CURRENT_WEATHER_XML;
59
        }
60
    }
61
62
    private function forecast($format)
63
    {
64
        if ($format == 'xml') {
65
            return FakeData::forecastXML();
66
        }
67
    }
68
69
    private function group($format)
70
    {
71
        if ($format == 'json') {
72
            return FakeData::WEATHER_GROUP_JSON;
73
        }
74
    }
75
}
76