BaseFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultFilterWithChild() 0 9 1
A defaultFilter() 0 11 1
A filterWithOptions() 0 8 1
1
<?php
2
namespace nstdio\svg\filter;
3
4
use nstdio\svg\container\ContainerInterface;
5
use nstdio\svg\SVGElement;
6
use nstdio\svg\util\KeyValueWriter;
7
8
/**
9
 * Class BaseFilter
10
 *
11
 * @property float  $x            = "<coordinate>" The minimum x coordinate for the subregion which restricts
12
 *           calculation and rendering of the given filter primitive.
13
 * @property float  $y            = "<coordinate>" The minimum y coordinate for the subregion which restricts
14
 *           calculation and rendering of the given filter primitive.
15
 * @property float  $width        = "<length>" The width of the subregion which restricts calculation and
16
 *           rendering of the given filter primitive. See filter primitive subregion. A negative value is an error. A
17
 *           value of zero disables the effect of the given filter primitive (i.e., the result is a transparent black
18
 *           image).
19
 * @property float  $height       = "<length>" The height of the subregion which restricts calculation and rendering of
20
 *           the given filter primitive. See filter primitive subregion. A negative value is an error (see Error
21
 *           processing). A value of zero disables the effect of the given filter primitive (i.e., the result is a
22
 *           transparent black image).
23
 * @property string $result       = "<filter-primitive-reference>" Assigned name for this filter primitive. If supplied,
24
 *           then graphics that result from processing this filter primitive can be referenced by an 'in' attribute on
25
 *           a subsequent filter primitive within the same 'filter' element. If no value is provided, the output will
26
 *           only be available for re-use as the implicit input into the next filter primitive if that filter primitive
27
 *           provides no value for its 'in' attribute. Note that a <filter-primitive-reference> is not an XML ID;
28
 *           instead, a <filter-primitive-reference> is only meaningful within a given 'filter' element and thus have
29
 *           only local scope. It is legal for the same <filter-primitive-reference> to appear multiple times within
30
 *           the same 'filter' element. When referenced, the <filter-primitive-reference> will use the closest
31
 *           preceding filter primitive with the given result.
32
 * @property string $in           = "SourceGraphic | SourceAlpha | BackgroundImage | BackgroundAlpha | FillPaint |
33
 *           StrokePaint | <filter-primitive-reference>" Identifies input for the given filter primitive. The value can
34
 *           be either one of six keywords or can be a string which matches a previous 'result' attribute value within
35
 *           the same 'filter' element. If no value is provided and this is the first filter primitive, then this
36
 *           filter primitive will use SourceGraphic as its input. If no value is provided and this is a subsequent
37
 *           filter primitive, then this filter primitive will use the result from the previous filter primitive as its
38
 *           input. {@link https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveInAttribute}
39
 * @package  nstdio\svg\filter
40
 * @author   Edgar Asatryan <[email protected]>
41
 */
42
abstract class BaseFilter extends SVGElement
43
{
44 5
    protected static function defaultFilterWithChild(ContainerInterface $container, array $options)
45
    {
46 5
        $filter = self::defaultFilter($container, $options['id']);
47 5
        unset($options['id']);
48 5
        $child = new static($filter);
49 5
        KeyValueWriter::apply($child->getElement(), $options);
0 ignored issues
show
Bug introduced by
It seems like $child->getElement() targeting nstdio\svg\SVGElement::getElement() can also be of type object<DOMElement> or object<nstdio\svg\container\ContainerInterface>; however, nstdio\svg\util\KeyValueWriter::apply() does only seem to accept object<nstdio\svg\XMLDocumentInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
50
51 5
        return $filter;
52
    }
53
54
    /**
55
     * @param ContainerInterface  $container
56
     * @param                     $filterId
57
     *
58
     * @return Filter
59
     */
60 16
    protected static function defaultFilter(ContainerInterface $container, $filterId)
61
    {
62 16
        return self::filterWithOptions($container, [
63 16
            'id'          => $filterId,
64 16
            'filterUnits' => 'objectBoundingBox',
65 16
            'x'           => '0%',
66 16
            'y'           => '0%',
67 16
            'width'       => '100%',
68 16
            'height'      => '100%',
69 16
        ]);
70
    }
71
72 17
    protected static function filterWithOptions(ContainerInterface $container, array $options)
73
    {
74 17
        $filter = new Filter($container, $options['id']);
75 17
        unset($options['id']);
76 17
        KeyValueWriter::apply($filter->getElement(), $options);
0 ignored issues
show
Bug introduced by
It seems like $filter->getElement() targeting nstdio\svg\SVGElement::getElement() can also be of type object<DOMElement> or object<nstdio\svg\container\ContainerInterface>; however, nstdio\svg\util\KeyValueWriter::apply() does only seem to accept object<nstdio\svg\XMLDocumentInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
77
78 17
        return $filter;
79
    }
80
}