OpenStreet::getMapUrl()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 15

Duplication

Lines 21
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 21
loc 21
rs 8.7624
cc 5
eloc 15
nc 5
nop 0
1
<?php
2
/**
3
 * Codru Components
4
 *
5
 * @author Maxim Vasiliev <[email protected]>
6
 * @license http://www.opensource.org/licenses/bsd-license.php
7
 */
8
9
namespace codru\staticmap\types;
10
11
use codru\staticmap\MapType;
12
use yii\base\Object;
13
14 View Code Duplication
class OpenStreet extends Object implements MapType
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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