StaticMapSaverForHTTPS   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 25
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert_to_local_file() 0 14 4
1
<?php
2
3
/**
4
 * save a map to a local file.
5
 *
6
 *
7
 */
8
9
class StaticMapSaverForHTTPS extends Object
10
{
11
    private static $save_dir = "assets";
12
13
    private static $overwrite = false;
14
15
    /**
16
     * @param String $url
17
     * @param String $filename
18
     */
19
    public function convert_to_local_file($url, $filename)
20
    {
21
        $fileFolder = self::$save_dir.'/'.$filename;
22
        $target = Director::baseFolder().'/'.$fileFolder;
23
        if (file_exists($target) && !self::$overwrite) {
24
            return $fileFolder;
25
        }
26
        $fh = fopen($target, 'w');
27
        $check = fwrite($fh, file_get_contents($url));
28
        fclose($fh);
29
        if ($check) {
30
            return $fileFolder;
31
        }
32
    }
33
}
34