RectangularFromTwoPoints   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 30.95 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 13
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A produce() 13 13 3

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 CGI-Calc package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cgi\Calc\Field;
13
14
use Cgi\Calc\Point;
15
use Cgi\Calc\Point\PointSet;
16
17
class RectangularFromTwoPoints extends AbstractFieldProducer
18
{
19
    /** @var Point */
20
    private $lowerLeft;
21
22
    /** @var Point */
23
    private $upperRight;
24
25
    /**
26
     * @param Point                  $lowerLeft
27
     * @param Point                  $upperRight
28
     * @param ValueProvider|callable $valueProvider
29
     */
30
    public function __construct(Point $lowerLeft, Point $upperRight, $valueProvider = null)
31
    {
32
        parent::__construct($valueProvider);
33
34
        if ($lowerLeft->isRight($upperRight) || $lowerLeft->isAbove($upperRight)) {
35
            throw new \InvalidArgumentException('First point must not be right or above of the second point');
36
        }
37
38
        $this->lowerLeft = $lowerLeft;
39
        $this->upperRight = $upperRight;
40
    }
41
42
    /**
43
     * @return PointSet
44
     */
45 View Code Duplication
    public function produce()
0 ignored issues
show
Duplication introduced by
This method 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...
46
    {
47
        $result = new PointSet();
48
        foreach ($this->lowerLeft->forXUpTo($this->upperRight) as $x) {
49
            foreach ($this->lowerLeft->forYUpTo($this->upperRight) as $y) {
50
                $point = new Point($x, $y);
51
                $value = $this->getValue($point);
52
                $result->attach($point, $value);
53
            }
54
        }
55
56
        return $result;
57
    }
58
}
59