Test Failed
Push — master ( 483f83...a6b1f2 )
by Edgar
03:01
created

Line::toPolygon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
namespace nstdio\svg\shape;
3
4
use nstdio\svg\ElementInterface;
5
6
/**
7
 * Class Line
8
 * The 'line' element defines a line segment that starts at one point and ends at another.
9
 *
10
 * @link    https://www.w3.org/TR/SVG11/shapes.html#LineElement
11
 * @property float x1 The x-axis coordinate of the start of the line. If the attribute is not specified, the effect is
12
 *           as if a value of "0" were specified.
13
 * @property float y1 The y-axis coordinate of the start of the line. If the attribute is not specified, the effect is
14
 *           as if a value of "0" were specified.
15
 * @property float x2 The x-axis coordinate of the end of the line. If the attribute is not specified, the effect is as
16
 *           if a value of "0" were specified.
17
 * @property float y2 The y-axis coordinate of the end of the line. If the attribute is not specified, the effect is as
18
 *           if a value of "0" were specified.
19
 *
20
 * @package shape
21
 * @author  Edgar Asatryan <[email protected]>
22
 */
23
class Line extends Shape
24
{
25
    /**
26
     * Line constructor.
27
     *
28
     * @param ElementInterface $parent
29
     * @param int              $x1
30
     * @param int              $y1
31
     * @param int              $x2
32
     * @param int              $y2
33
     */
34 16
    public function __construct(ElementInterface $parent, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0)
35
    {
36 16
        parent::__construct($parent);
37
38 16
        $this->x1 = $x1;
39 16
        $this->y1 = $y1;
40 16
        $this->x2 = $x2;
41 16
        $this->y2 = $y2;
42 16
    }
43
44
    /**
45
     * @param ElementInterface $parent
46
     * @param                  $x1
47
     * @param                  $y1
48
     * @param                  $x2
49
     * @param                  $y2
50
     *
51
     * @return Line
52
     */
53 5
    public static function create(ElementInterface $parent, $x1, $y1, $x2, $y2)
54
    {
55 5
        return new Line($parent, $x1, $y1, $x2, $y2);
56
    }
57
58
    /**
59
     * @param bool $closePath
60
     *
61
     * @return Path
62
     */
63 1
    public function toPath($closePath = false)
64
    {
65 1
        $path = Path::line($this->getRoot(), $this->x1, $this->y1, $this->x2, $this->y2);
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\ElementInterface>.

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...
66
67 1
        if ($closePath === true) {
68 1
            $path->closePath();
69 1
        }
70
71 1
        return $path;
72
    }
73
74
    /**
75
     * @return Polygon
76
     */
77 1
    public function toPolygon()
78
    {
79 1
        $polygon = new Polygon($this->getRoot());
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\ElementInterface>.

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...
80 1
        $polygon->addPointArray([
81 1
            [$this->x1, $this->y1],
82 1
            [$this->x2, $this->y2],
83 1
        ]);
84
85 1
        return $polygon;
86
    }
87
88 16
    public function getName()
89
    {
90 16
        return 'line';
91
    }
92
93 1
    public function getBoundingBox()
94
    {
95 1
        return Rect::boxFromPoints($this->x1, $this->y1, $this->x2, $this->y2);
96
    }
97
98 3
    protected function getCenterX()
99
    {
100 3
        return abs($this->x2 - $this->x1) / 2;
101
    }
102
103 3
    protected function getCenterY()
104
    {
105 3
        return abs($this->y2 - $this->y1) / 2;
106
    }
107
}