Completed
Pull Request — master (#22)
by Daryl
01:32
created

Map_Model   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 1
dl 44
loc 44
ccs 12
cts 13
cp 0.9231
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A has_map() 5 5 1
A __call() 21 21 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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

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
/**
8
 * Class Map_Model
9
 * @package Clubdeuce\WPLib\Components\GoogleMaps
10
 *
11
 * @mixin Map
12
 */
13 View Code Duplication
class Map_Model extends Model_Base {
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...
14
15
	/**
16
	 * @var Map
17
	 */
18
	protected $_map;
19
20
	/**
21
	 * @return bool
22
	 */
23 2
	function has_map() {
24
25 2
		return $this->_has('_map' );
26
27
	}
28
29
	/**
30
	 * @param  string $method_name
31
	 * @param  array  $args
32
	 *
33
	 * @return mixed
34
	 */
35 2
	function __call( $method_name, $args = array() ) {
36 2
		$value = null;
37
38
		do {
39
40 2
			if ( property_exists( $this, "_{$method_name}" ) ) {
41 1
				$property = "_{$method_name}";
42 1
				$value = $this->{$property};
43 1
				break;
44
			}
45
46 2
			if ( ! isset( $this->_map ) ) {
47
				break;
48
			}
49
50 2
			$value = call_user_func_array( array( $this->_map, $method_name ), $args );
51
52 2
		} while ( false );
53
54 2
		return $value;
55
	}
56
}
57