Completed
Push — master ( e000b3...b0a3db )
by Christopher
06:52 queued 48s
created

AggregateRoot::makeEntity()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4286
ccs 10
cts 10
cp 1
cc 3
eloc 9
nc 3
nop 0
crap 3
1
<?php namespace C4tech\RayEmitter\Domain;
2
3
use C4tech\RayEmitter\Contracts\Domain\AggregateRoot as AggregateRootInterface;
4
use C4tech\RayEmitter\Exceptions\UnknownProperty;
5
6
trait AggregateRoot // extends AggregateRootInterface
7
{
8
    /**
9
     * @inheritDoc
10
     */
11 1
    public function makeEntity()
12
    {
13 1
        $class = get_parent_class($this);
14 1
        $entity = new $class($this->getId());
0 ignored issues
show
Bug introduced by
It seems like getId() 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...
15
16 1
        $properties = get_object_vars($this);
17 1
        foreach ($properties as $key => $value) {
18 1
            if ($key === 'identity') {
19 1
                continue;
20
            }
21
22 1
            $entity->set($key, $value);
23 1
        }
24
25 1
        return $entity;
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31 1
    public function __set($property, $value)
32
    {
33 1
        $this->set($property, $value);
0 ignored issues
show
Bug introduced by
It seems like set() 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...
34 1
    }
35
}
36