Code Duplication    Length = 33-33 lines in 2 locations

types/Google.php 1 location

@@ 14-46 (lines=33) @@
11
use codru\staticmap\MapType;
12
use yii\base\Object;
13
14
class Google extends Object implements MapType
15
{
16
    const GOOGLE_MAP_URI = 'http://maps.googleapis.com/maps/api/staticmap?';
17
18
    public $options;
19
20
    public function getMapUrl()
21
    {
22
        $url = static::GOOGLE_MAP_URI;
23
        foreach ($this->options as $key => $value) {
24
            if (is_array($value)) {
25
                $url .= $key . '=';
26
                foreach ($value as $k => $v) {
27
                    if (!is_numeric($k)) {
28
                        $url .= $k . ':' . $v . '|';
29
                    } else {
30
                        $url .= $v . '|';
31
                    }
32
                }
33
                $url = $this->cutLastSymbol($url);
34
            } else {
35
                $url .= $key . '=' . $value . '&';
36
            }
37
        }
38
        $url = $this->cutLastSymbol($url);
39
        return $url;
40
    }
41
42
    private function cutLastSymbol($str)
43
    {
44
        return substr($str, 0, -1);
45
    }
46
}
47

types/OpenStreet.php 1 location

@@ 14-46 (lines=33) @@
11
use codru\staticmap\MapType;
12
use yii\base\Object;
13
14
class OpenStreet extends Object implements MapType
15
{
16
    const OPENSTREET_MAP_URI = 'http://staticmap.openstreetmap.de/staticmap.php?';
17
18
    public $options;
19
20
    public function getMapUrl()
21
    {
22
        $url = static::OPENSTREET_MAP_URI;
23
        foreach ($this->options as $key => $value) {
24
            if (is_array($value)) {
25
                $url .= $key . '=';
26
                foreach ($value as $k => $v) {
27
                    if (!is_numeric($k)) {
28
                        $url .= $k . ':' . $v . '|';
29
                    } else {
30
                        $url .= $v . ',';
31
                    }
32
                }
33
                $url = $this->cutLastSymbol($url);
34
            } else {
35
                $url .= $key . '=' . $value . '&';
36
            }
37
        }
38
        $url = $this->cutLastSymbol($url);
39
        return $url;
40
    }
41
42
    private function cutLastSymbol($str)
43
    {
44
        return substr($str, 0, -1);
45
    }
46
}
47