Completed
Pull Request — master (#22)
by Daryl
02:30
created

includes/class-location-model.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps;
4
use Clubdeuce\WPGoogleMaps\Location;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Clubdeuce\WPLib\Components\GoogleMaps\Location.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
6
/**
7
 * Class Location_Model
8
 * @package Clubdeuce\WPLib\Components\GoogleMaps
9
 * @method  string address()
10
 * @method  string formatted_address()
11
 * @method  string state()
12
 * @method  string zip_code()
13
 * @method  float  latitude()
14
 * @method  string location_type()
15
 * @method  float  longitude()
16
 * @method  string place_id()
17
 * @method  array  type()
18
 * @method  array  viewport()
19
 */
20
class Location_Model extends Model_Base {
21
22
    /**
23
     * @var \Clubdeuce\WPGoogleMaps\Location
24
     */
25
    protected $_location;
26
27
	/**
28
	 * Location_Model constructor.
29
	 *
30
	 * @param array $args
31
	 */
32 4
	function __construct( $args = array() ) {
33
34 4
		$location = new Location( $args );
35
36 4
		$args = wp_parse_args( $args, array(
37 4
			'location' => $location,
38
		) );
39
40 4
		parent::__construct( $args );
41
42 4
	}
43
44
	/**
45
	 * @return bool
46
	 */
47 1
	function has_location() {
48
49 1
		return $this->_has( '_location' );
50
51
	}
52
53
    /**
54
     * @param  string $method_name
55
     * @return mixed
56
     */
57 4
    public function __call( $method_name, $args ) {
58 4
        $value = null;
59
60
	    do {
61
62 4
		    if ( property_exists( $this, "_{$method_name}" ) ) {
63 2
			    $property = "_{$method_name}";
64 2
			    $value = $this->{$property};
65 2
			    break;
66
		    }
67
68 2
		    if ( ! isset( $this->_location ) ) {
69 1
		    	break;
70
		    }
71
72 1
		    $value = call_user_func_array( array( $this->_location, $method_name ), $args );
73
74 1
	    } while ( false );
75
76 4
        return $value;
77
    }
78
79
}
80