GlobalWeather   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 51
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCurrentWeather() 0 5 1
A getWeatherResultXML() 0 14 2
1
<?php
2
namespace Dwr\GlobalWeatherBundle\WeatherService;
3
4
use Dwr\GlobalWeatherBundle\Utility\ParserXML;
5
use Dwr\GlobalWeatherBundle\Entity\Location;
6
use Dwr\GlobalWeatherBundle\WeatherService\Client\GlobalWeatherClient as GlobalWeatherClient;
7
8
class GlobalWeather
9
{
10
    /**
11
     * @var \SoapClient
12
     */
13
    private $globalWeatherClient;
14
15
    /**
16
     * @var ParserXML
17
     */
18
    private $parserXML;
19
20
    /**
21
     * @param GlobalWeatherClient $client
22
     * @param ParserXML $parserXML
23
     */
24
    public function __construct(GlobalWeatherClient $client, ParserXML $parserXML)
25
    {
26
        $this->globalWeatherClient = $client->connect();
27
        $this->parserXML = $parserXML;
28
    }
29
30
    /**
31
     * @param Location $location
32
     * @return boolean|\SimpleXMLElement
33
     */
34
    public function getCurrentWeather(Location $location)
35
    {
36
        $xml = $this->getWeatherResultXML($location);
37
        return $this->parserXML->parseXML($xml);
38
    }
39
40
    /**
41
     * @param Location $location
42
     * @return boolean
43
     */
44
    private function getWeatherResultXML(Location $location)
45
    {
46
        try {
47
            $globalWeather = $this->globalWeatherClient->GetWeather(
48
                [
49
                    'CityName' => $location->getCity(),
50
                    'CountryName' => $location->getCountry()
51
                ]
52
            );
53
            return $globalWeather->GetWeatherResult;
54
        } catch (\Exception $e) {
55
            return false;
56
        }
57
    }
58
}
59