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

CurlFetcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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