StaticMapSaverForHTTPS::convert_to_local_file()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 3
nop 2
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