Completed
Push — master ( 6b73b6...a2735d )
by Edgar
03:29
created

Shape::radialGradientFromBottomRight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
namespace nstdio\svg\shape;
3
4
use nstdio\svg\animation\BaseAnimation;
5
use nstdio\svg\ElementInterface;
6
use nstdio\svg\filter\BaseFilter;
7
use nstdio\svg\filter\DiffuseLighting;
8
use nstdio\svg\filter\Filter;
9
use nstdio\svg\filter\GaussianBlur;
10
use nstdio\svg\gradient\Gradient;
11
use nstdio\svg\gradient\UniformGradient;
12
use nstdio\svg\SVGElement;
13
use nstdio\svg\traits\StyleTrait;
14
use nstdio\svg\traits\TransformTrait;
15
use nstdio\svg\util\Transform;
16
17
/**
18
 * Class Shape
19
 *
20
 * @property float  height      The height of shape.
21
 * @property float  width       The width of shape.
22
 * @property string stroke      Stroke color.
23
 * @property float  strokeWidth Width of stroke.
24
 * @property string strokeLocation
25
 * @property string style
26
 * @property string fill
27
 * @property string fillUrl     The id part of fill attribute.
28
 * @property float  fillOpacity specifies the opacity of the painting operation used to paint the interior the
29
 *           current
30
 * @property string filter
31
 * @property string filterUrl   The id part of filter attribute.
32
 * @property string transform
33
 * @package nstdio\svg\shape
34
 * @author  Edgar Asatryan <[email protected]>
35
 */
36
abstract class Shape extends SVGElement implements ShapeInterface
37
{
38
    use StyleTrait, TransformTrait;
39
40
    abstract protected function getCenterX();
41
42
    abstract protected function getCenterY();
43
44
    abstract public function getBoundingBox();
45
46 73
    public function __construct(ElementInterface $parent)
47
    {
48 73
        parent::__construct($parent);
49
50 73
        $this->transformImpl = Transform::newInstance($this->getTransformAttribute());
51 73
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56 73
    public function getTransformAttribute()
57
    {
58 73
        return $this->transform;
59
    }
60
61 1
    public function setTransformAttribute($transformList)
62
    {
63 1
        $this->transform = $transformList;
64 1
    }
65
66 17
    public function applyGradient(Gradient $gradient)
67 1
    {
68 17
        $this->fillUrl = $gradient->id;
69
70 17
        return $this;
71
    }
72
73 4
    public function animate(BaseAnimation $animation)
74
    {
75 4
        $this->element->appendChild($animation->getElement());
76
77 1
        return $this;
78
    }
79
80 2
    public function filterGaussianBlur($stdDeviation, $in = null, $filterId = null)
81
    {
82 2
        $filter = new Filter($this->getRoot(), $filterId);
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...
83 2
        $blur = new GaussianBlur($filter);
84 2
        $blur->stdDeviation = $stdDeviation;
85 2
        $blur->in = $in;
86
87 2
        $this->applyFilter($filter);
88
89 2
        return $this;
90
    }
91
92 1
    public function diffusePointLight(array $pointLightConfig = [], array $diffuseLightingConfig = [], $filterId = null)
93
    {
94
        $pointConfig = [
95 1
            'x' => $this->getCenterX(),
96 1
            'y' => $this->getCenterY(),
97 1
            'z' => 25,
98 1
        ];
99 1
        foreach ($pointConfig as $key => $value) {
100 1
            if (isset($pointLightConfig[$key])) {
101 1
                $pointConfig[$key] = $value + $pointLightConfig[$key];
102 1
            }
103 1
        }
104 1
        $filter = DiffuseLighting::diffusePointLight($this->getRoot(), $pointConfig, $diffuseLightingConfig, $filterId);
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
105 1
        $this->applyFilter($filter);
106
107 1
        return $this;
108
    }
109
110 3
    public function applyFilter(BaseFilter $filter)
111
    {
112 3
        $svg = $this->getSVG();
113 3
        if ($this->filter === null) {
114 3
            $this->filterUrl = $filter->id;
115 3
            $defs = $svg->getFirstChild();
116 3
            $filter->selfRemove();
1 ignored issue
show
Bug introduced by
The method selfRemove() cannot be called from this context as it is declared protected in class nstdio\svg\SVGElement.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
117 3
            $defs->append($filter);
118 3
        } else {
119 1
            $currentFilter = $svg->getFirstChild()->getChildById($this->filterUrl);
120 1
            if ($currentFilter !== null) {
121 1
                foreach ($filter->getChildren() as $child) {
122 1
                    $currentFilter->append($child);
123 1
                }
124 1
                $filter->selfRemove();
1 ignored issue
show
Bug introduced by
The method selfRemove() cannot be called from this context as it is declared protected in class nstdio\svg\SVGElement.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
125 1
            }
126
        }
127
128 3
        return $this;
129
    }
130
131 1
    public function linearGradientFromTop(array $colors, $id = null)
132
    {
133 1
        return $this->applyGradient(UniformGradient::verticalFromTop($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
134
    }
135
136 1
    public function linearGradientFromBottom(array $colors, $id = null)
137
    {
138 1
        return $this->applyGradient(UniformGradient::verticalFromBottom($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
139
    }
140
141 1
    public function linearGradientFromLeft(array $colors, $id = null)
142
    {
143 1
        return $this->applyGradient(UniformGradient::horizontalFromLeft($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
144
    }
145
146 1
    public function linearGradientFromRight(array $colors, $id = null)
147
    {
148 1
        return $this->applyGradient(UniformGradient::horizontalFromRight($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
149
    }
150
151 1
    public function linearGradientFromTopLeft(array $colors, $id = null)
152
    {
153 1
        return $this->applyGradient(UniformGradient::diagonalFromTopLeft($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
154
    }
155
156 1
    public function linearGradientFromTopRight(array $colors, $id = null)
157
    {
158 1
        return $this->applyGradient(UniformGradient::diagonalFromTopRight($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
159
    }
160
161 1
    public function linearGradientFromBottomLeft(array $colors, $id = null)
162
    {
163 1
        return $this->applyGradient(UniformGradient::diagonalFromBottomLeft($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
164
    }
165
166 1
    public function linearGradientFromBottomRight(array $colors, $id = null)
167
    {
168 1
        return $this->applyGradient(UniformGradient::diagonalFromBottomRight($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
169
    }
170
171 1
    public function radialGradientFromTopLeft(array $colors, $id = null)
172
    {
173 1
        return $this->applyGradient(UniformGradient::radialTopLeft($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
174
    }
175
176 1
    public function radialGradientFromTopRight(array $colors, $id = null)
177
    {
178 1
        return $this->applyGradient(UniformGradient::radialTopRight($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
179
    }
180
181 1
    public function radialGradientFromBottomLeft(array $colors, $id = null)
182
    {
183 1
        return $this->applyGradient(UniformGradient::radialBottomLeft($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
184
    }
185
186 1
    public function radialGradientFromBottomRight(array $colors, $id = null)
187
    {
188 1
        return $this->applyGradient(UniformGradient::radialBottomRight($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
189
    }
190
191 1
    public function radialGradientFromTopCenter(array $colors, $id = null)
192
    {
193 1
        return $this->applyGradient(UniformGradient::radialTopCenter($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
194
    }
195
196 1
    public function radialGradientFromLeftCenter(array $colors, $id = null)
197
    {
198 1
        return $this->applyGradient(UniformGradient::radialLeftCenter($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
199
    }
200
201 1
    public function radialGradientFromBottomCenter(array $colors, $id = null)
202
    {
203 1
        return $this->applyGradient(UniformGradient::radialBottomCenter($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
204
    }
205
206 1
    public function radialGradientFromRightCenter(array $colors, $id = null)
207
    {
208 1
        return $this->applyGradient(UniformGradient::radialRightCenter($this->getRoot(), $colors, $id));
0 ignored issues
show
Documentation introduced by
$this->getRoot() is of type object<nstdio\svg\XMLDocumentInterface>, but the function expects a object<nstdio\svg\container\ContainerInterface>.

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...
209
    }
210
}