RectangularFromTwoPoints::produce()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 3
eloc 8
nc 3
nop 0
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