Completed
Push — master ( d8adec...3d8ab4 )
by Daryl
03:59
created

Map_View::_make_info_windows()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps;
4
5
/**
6
 * Class Map_View
7
 * @package  Clubdeuce\GoogleMaps
8
 * @property Map $item
9
 */
10
class Map_View extends \WPLib_View_Base {
11
12
    function the_map() {
13
14
        $height       = $this->item->height();
0 ignored issues
show
Documentation Bug introduced by
The method height does not exist on object<Clubdeuce\WPLib\Components\GoogleMaps\Map>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
15
        $width        = $this->item->width();
0 ignored issues
show
Documentation Bug introduced by
The method width does not exist on object<Clubdeuce\WPLib\Components\GoogleMaps\Map>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
16
        $map_id       = $this->item->html_id();
0 ignored issues
show
Documentation Bug introduced by
The method html_id does not exist on object<Clubdeuce\WPLib\Components\GoogleMaps\Map>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
17
        $map_params   = $this->item->make_args();
18
        $markers      = $this->_make_markers_args();
19
        $info_windows = $this->_make_info_windows();
20
21
        require dirname( __DIR__) . '/templates/map-view.php';
22
23
    }
24
25
    /**
26
     * @return array
27
     */
28
    private function _make_markers_args() {
29
30
        /**
31
         * @var Marker $marker
32
         */
33
        return array_map( function( $marker ) {
34
            return $marker->make_options();
35
        }, $this->item->markers() );
36
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    protected function _make_info_windows() {
43
44
        $windows = array();
45
46
        /**
47
         * @var Marker $marker
48
         */
49
        foreach( $this->item->markers() as $marker ) {
50
            $windows[] = array(
51
                'content'      => $marker->info_window()->content(),
52
                'pixel_offset' => $marker->info_window()->pixel_offset(),
53
                'position'     => $marker->info_window()->position(),
54
                'max_width'    => $marker->info_window()->max_width(),
55
            );
56
        }
57
58
        return $windows;
59
60
    }
61
}
62