Polygon   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 74
loc 74
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A hasCoordinates() 4 4 1
A getCoordinates() 4 4 1
A setCoordinates() 5 5 1
A addCoordinates() 6 6 2
A hasCoordinate() 4 4 1
A addCoordinate() 4 4 1
A removeCoordinate() 5 5 2

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
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Overlay;
13
14
use Ivory\GoogleMap\Base\Coordinate;
15
use Ivory\GoogleMap\Utility\OptionsAwareInterface;
16
use Ivory\GoogleMap\Utility\OptionsAwareTrait;
17
use Ivory\GoogleMap\Utility\VariableAwareTrait;
18
19
/**
20
 * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Polygon
21
 *
22
 * @author GeLo <[email protected]>
23
 */
24 View Code Duplication
class Polygon implements ExtendableInterface, OptionsAwareInterface
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...
25
{
26
    use OptionsAwareTrait;
27
    use VariableAwareTrait;
28
29
    /**
30
     * @var Coordinate[]
31
     */
32
    private $coordinates = [];
33
34
    /**
35
     * @param Coordinate[] $coordinates
36
     * @param mixed[]      $options
37
     */
38 40
    public function __construct(array $coordinates = [], array $options = [])
39
    {
40 40
        $this->addCoordinates($coordinates);
41 40
        $this->addOptions($options);
42 40
    }
43
44
    /**
45
     * @return bool
46
     */
47 24
    public function hasCoordinates()
48
    {
49 24
        return !empty($this->coordinates);
50
    }
51
52
    /**
53
     * @return Coordinate[]
54
     */
55 32
    public function getCoordinates()
56
    {
57 32
        return $this->coordinates;
58
    }
59
60
    /**
61
     * @param Coordinate[] $coordinates
62
     */
63 8
    public function setCoordinates(array $coordinates)
64
    {
65 8
        $this->coordinates = [];
66 8
        $this->addCoordinates($coordinates);
67 8
    }
68
69
    /**
70
     * @param Coordinate[] $coordinates
71
     */
72 40
    public function addCoordinates(array $coordinates)
73
    {
74 40
        foreach ($coordinates as $coordinate) {
75 20
            $this->addCoordinate($coordinate);
76
        }
77 40
    }
78
79
    /**
80
     * @return bool
81
     */
82 16
    public function hasCoordinate(Coordinate $coordinate)
83
    {
84 16
        return in_array($coordinate, $this->coordinates, true);
85
    }
86
87 28
    public function addCoordinate(Coordinate $coordinate)
88
    {
89 28
        $this->coordinates[] = $coordinate;
90 28
    }
91
92 4
    public function removeCoordinate(Coordinate $coordinate)
93
    {
94 4
        unset($this->coordinates[array_search($coordinate, $this->coordinates, true)]);
95 4
        $this->coordinates = empty($this->coordinates) ? [] : array_values($this->coordinates);
96 4
    }
97
}
98