CircularCenterRadiusTest::test_draw()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 2
eloc 15
nc 2
nop 0
1
<?php
2
3
namespace Cgi\Calc\Tests\Field;
4
5
use Cgi\Calc\Field\CircularCenterRadius;
6
use Cgi\Calc\Field\RectangularFromTwoPoints;
7
use Cgi\Calc\Point;
8
use Cgi\Calc\PointSet;
9
10
class CircularCenterRadiusTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function test_draw()
13
    {
14
        $circularProducer = new CircularCenterRadius(new Point(15,15), 10, true);
15
        $circle = $circularProducer->produce();
16
17
        $circle->smallestRectangularEnvelope();
18
        $rectangularProducer = new RectangularFromTwoPoints(new Point(0,0), new Point(30, 30));
19
        $rect = $rectangularProducer->produce();
20
21
        if (false) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
22
            $this->doDraw($circle, $rect);
0 ignored issues
show
Documentation introduced by
$circle is of type object<Cgi\Calc\Point\PointSet>, but the function expects a object<Cgi\Calc\PointSet>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$rect is of type object<Cgi\Calc\Point\PointSet>, but the function expects a object<Cgi\Calc\PointSet>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
        }
24
25
        static::assertFalse($circle->contains(new Point(11, 5)));
26
        static::assertTrue($circle->contains(new Point(12, 5)));
27
28
        static::assertTrue($circle->contains(new Point(15, 15)));
29
30
        static::assertTrue($circle->contains(new Point(15, 5)));
31
        static::assertTrue($circle->contains(new Point(15, 25)));
32
33
        static::assertTrue($circle->contains(new Point(5, 15)));
34
        static::assertTrue($circle->contains(new Point(25, 15)));
35
    }
36
37
    private function doDraw(PointSet $circle, PointSet $rect)
38
    {
39
        $arr = [];
40
        /** @var Point $point */
41
        foreach ($rect as $point) {
42
            $arr[$point->getY()][$point->getX()] = '.';
43
        }
44
        foreach ($circle as $point) {
45
            $arr[$point->getY()][$point->getX()] = 'X';
46
        }
47
48
        print "\n\n\n\n";
49
        $firstLine = true;
50
        for ($y=0, $yMax = count($arr); $y<$yMax; $y++) {
51
            $row = $arr[$y];
52
            if ($firstLine) {
53
                $firstLine = false;
54
                print 'y  ';
55 View Code Duplication
                for ($x=0, $xMax = count($row); $x<$xMax; $x++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
56
                    print $x % 10;
57
                }
58
                print " x \n";
59
            }
60
            print str_pad($y, 3);
61 View Code Duplication
            for ($x=0, $xMax = count($row); $x<$xMax; $x++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
62
                print $row[$x];
63
            }
64
            print "\n";
65
        }
66
        print "\n\n\n\n";
67
    }
68
}
69