Completed
Push — master ( fb3943...fbbc4e )
by Edgar
04:02
created

ElementTrait::attributes()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
namespace nstdio\svg\traits;
3
4
use nstdio\svg\ElementInterface;
5
use nstdio\svg\XMLDocumentInterface;
6
7
/**
8
 * Trait ElementTrait
9
 *
10
 * @package nstdio\svg\traits
11
 * @author  Edgar Asatryan <[email protected]>
12
 */
13
trait ElementTrait
14
{
15
    /**
16
     * @param ElementInterface|ElementInterface[] $elements
17
     *
18
     * @return $this
19
     */
20
    public function append(ElementInterface $elements)
0 ignored issues
show
Unused Code introduced by
The parameter $elements is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        /** @var ElementInterface[] $elements */
23 149
        $elements = array_filter(func_get_args(), function ($item) {
24 149
            return $item instanceof ElementInterface;
25 149
        });
26
27 149
        foreach ($elements as $element) {
28 149
            $this->child[] = $element;
0 ignored issues
show
Bug introduced by
The property child does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
            /** @var \DOMElement $e */
30 149
            $e = $this->getElement();
0 ignored issues
show
Bug introduced by
It seems like getElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31 149
            if ($e instanceof \DOMNode) {
32 149
                $e->appendChild($element->getElement()->getElement());
0 ignored issues
show
Bug introduced by
The method getElement() does not exist on DOMElement. Did you maybe mean getElementsByTagName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
33 149
            } elseif ($e instanceof XMLDocumentInterface) {
34 74
                $e->appendChild($element->getElement());
35 74
            }
36 149
        }
37
38 149
        return $this;
39
    }
40
}