Completed
Branch dev (70bfe7)
by Edgar
03:44
created

Shape::linearGradientFromLeft()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace nstdio\svg\shape;
3
4
use nstdio\svg\Animatable;
5
use nstdio\svg\animation\BaseAnimation;
6
use nstdio\svg\attributes\Styleable;
7
use nstdio\svg\filter\BaseFilter;
8
use nstdio\svg\filter\DiffuseLighting;
9
use nstdio\svg\filter\Filter;
10
use nstdio\svg\filter\GaussianBlur;
11
use nstdio\svg\Filterable;
12
use nstdio\svg\gradient\Gradient;
13
use nstdio\svg\gradient\UniformGradient;
14
use nstdio\svg\SVGElement;
15
use nstdio\svg\traits\StyleTrait;
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 float       fillOpacity specifies the opacity of the painting operation used to paint the interior the
28
 *           current
29
 * @property string      filter
30
 * @property string|null filterUrl The url part of filter.
31
 * @property string transform
32
 * @package nstdio\svg\shape
33
 * @author  Edgar Asatryan <[email protected]>
34
 */
35
abstract class Shape extends SVGElement implements Styleable, Animatable, Filterable
36
{
37
    use StyleTrait;
38
39
    public function applyGradient(Gradient $gradient)
40
    {
41
        $this->fill = "url(#{$gradient->id})";
42
43
        return $this;
44
    }
45
46
    public function animate(BaseAnimation $animation)
47
    {
48
        $this->element->appendChild($animation->getElement());
0 ignored issues
show
Bug introduced by
The method appendChild() does not seem to exist on object<nstdio\svg\ElementInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
50
        return $this;
51
    }
52
53
    public function filterGaussianBlur($stdDeviation, $in = null, $filterId = null)
54
    {
55
        $filter = new Filter($this->getRoot(), $filterId);
56
        $blur = new GaussianBlur($filter);
57
        $blur->stdDeviation = $stdDeviation;
58
        $blur->in = $in;
59
60
        $this->applyFilter($filter);
61
62
        return $this;
63
    }
64
65
    public function diffusePointLight(array $pointLightConfig = [], array $diffuseLightingConfig = [], $filterId = null)
66
    {
67
        $pointConfig = [
68
            'x' => $this->x,
0 ignored issues
show
Documentation introduced by
The property x does not exist on object<nstdio\svg\shape\Shape>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
69
            'y' => $this->y,
0 ignored issues
show
Documentation introduced by
The property y does not exist on object<nstdio\svg\shape\Shape>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
70
            'z' => 10,
71
        ];
72
        foreach ($pointConfig as $key => $value) {
73
            if (isset($pointLightConfig[$key])) {
74
                $pointConfig[$key] = $this->{$key} + $pointLightConfig[$key];
75
            }
76
        }
77
        $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...
78
        $this->applyFilter($filter);
79
80
        return $this;
81
    }
82
83
    public function applyFilter(BaseFilter $filter)
84
    {
85
        if ($this->filter === null) {
86
            $this->filter = "url(#$filter->id)";
87
        } else {
88
            $value = str_replace(['url(#', ')'], '', $this->filter);
89
            $svg = $this->getSVG();
90
            $currentFilter = $svg->getChildById($value);
91
            if ($currentFilter !== null) {
92
                foreach ($filter->getChildren() as $child) {
93
                    $currentFilter->append($child);
94
                }
95
                $filterRoot = $filter->getRoot();
96
                $filterRoot->removeChild($filter);
0 ignored issues
show
Bug introduced by
The method removeChild() does not seem to exist on object<nstdio\svg\XMLDocumentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
            }
98
        }
99
100
        return $this;
101
    }
102
103
    public function linearGradientFromTop(array $colors, $id = null)
104
    {
105
        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...
106
    }
107
108
    public function linearGradientFromBottom(array $colors, $id = null)
109
    {
110
        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...
111
    }
112
113
    public function linearGradientFromLeft(array $colors, $id = null)
114
    {
115
        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...
116
    }
117
118
    public function linearGradientFromRight(array $colors, $id = null)
119
    {
120
        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...
121
    }
122
123
    public function linearGradientFromTopLeft(array $colors, $id = null)
124
    {
125
        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...
126
    }
127
128
    public function linearGradientFromTopRight(array $colors, $id = null)
129
    {
130
        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...
131
    }
132
133
    public function linearGradientFromBottomLeft(array $colors, $id = null)
134
    {
135
        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...
136
    }
137
138
    public function linearGradientFromBottomRight(array $colors, $id = null)
139
    {
140
        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...
141
    }
142
143
    public function radialGradientFromTopLeft(array $colors, $id = null)
144
    {
145
        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...
146
    }
147
148
    public function radialGradientFromTopRight(array $colors, $id = null)
149
    {
150
        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...
151
    }
152
153
    public function radialGradientFromBottomLeft(array $colors, $id = null)
154
    {
155
        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...
156
    }
157
158
    public function radialGradientFromBottomRight(array $colors, $id = null)
159
    {
160
        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...
161
    }
162
163
    public function radialGradientFromTopCenter(array $colors, $id = null)
164
    {
165
        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...
166
    }
167
168
    public function radialGradientFromLeftCenter(array $colors, $id = null)
169
    {
170
        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...
171
    }
172
173
    public function radialGradientFromBottomCenter(array $colors, $id = null)
174
    {
175
        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...
176
    }
177
178
    public function radialGradientFromRightCenter(array $colors, $id = null)
179
    {
180
        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...
181
    }
182
}