Completed
Push — OpenWeatherMap-PHP-Api-17 ( 0a6ed3 )
by Christian
02:33
created

CurlFetcher   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 2
c 3
b 1
f 1
lcom 1
cbo 0
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fetch() 0 13 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\Fetcher;
19
20
/**
21
 * Class CurlFetcher.
22
 *
23
 * @internal
24
 */
25
class CurlFetcher implements FetcherInterface
26
{
27
    /**
28
     * @var array The Curl options to use.
29
     */
30
    private $curlOptions;
31
32
    /**
33
     * Create a new CurlFetcher instance.
34
     *
35
     * @param array $curlOptions The Curl options to use. See http://php.net/manual/de/function.curl-setopt.php
36
     * for a list of available options.
37
     */
38 3
    public function __construct($curlOptions = array())
39
    {
40 3
        $this->curlOptions = $curlOptions;
41 3
    }
42
    
43
    /**
44
     * {@inheritdoc}
45
     */
46 3
    public function fetch($url)
47
    {
48 3
        $ch = curl_init($url);
49 3
        curl_setopt($ch, CURLOPT_URL, $url);
50 3
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
51 3
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
52 3
        curl_setopt_array($ch, $this->curlOptions);
53
        
54 3
        $content = curl_exec($ch);
55 3
        curl_close($ch);
56
57 3
        return $content;
58
    }
59
}
60