Remote   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileContCurl() 0 10 1
A getFileContents() 0 13 4
A getUriScheme() 0 13 3
A getFileContFopen() 0 5 1
1
<?php
2
namespace GJClasses;
3
4
class Remote
5
{
6
    public function getFileContents($filename)
7
    {
8
        if (ini_get('allow_url_fopen') && extension_loaded('openssl')) {
9
10
            return $this->getFileContFopen($filename);
11
12
        } elseif (extension_loaded('curl')) {
13
14
            return $this->getFileContCurl($filename);
15
16
        } else {
17
18
            return false;
19
20
        }
21
    }
22
23
    public function getFileContFopen($filename)
24
    {
25
        $scheme = $this->getUriScheme($filename);
26
        $context = stream_context_create(array($scheme => array('header' => 'Connection: close\r\n')));
27
        return file_get_contents($filename, false, $context);
28
    }
29
30
    public function getUriScheme($filename)
31
    {
32
        if (substr($filename, 0, 6) == 'https:') {
33
34
            return 'https';
35
36
        } elseif (substr($filename, 0, 5) == 'http:') {
37
38
            return 'http';
39
40
        } else {
41
42
            return false;
43
44
        }
45
    }
46
47
    public function getFileContCurl($filename)
48
    {
49
        $handle = curl_init();
50
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
51
        curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
52
        curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
53
        curl_setopt($handle, CURLOPT_URL, $filename);
54
        $result = curl_exec($handle);
55
        curl_close($handle);
56
        return $result;
57
    }
58
}
59