Completed
Push — master ( aa6cd0...7372cb )
by Randy
02:05
created

Hydratable::append()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Dgame\Soap\Hydrator;
4
5
use Dgame\Soap\AssignableInterface;
6
7
/**
8
 * Class Hydratable
9
 * @package Dgame\Soap\Hydrator
10
 */
11
class Hydratable implements HydratableInterface
12
{
13
    /**
14
     * @param AssignableInterface $assignable
15
     */
16
    public function assign(AssignableInterface $assignable)
17
    {
18
        if ($assignable->hasValue()) {
19
            $this->assignValue($assignable->getName(), $assignable->getValue());
20
        }
21
    }
22
23
    /**
24
     * @param HydratableInterface $hydratable
25
     *
26
     * @return bool
27
     */
28
    public function append(HydratableInterface $hydratable): bool
29
    {
30
        return Method::of($hydratable->getClassName(), $this)->assign($hydratable);
31
    }
32
33
    /**
34
     * @param string $name
35
     * @param string $value
36
     */
37
    public function assignValue(string $name, string $value)
38
    {
39
        if (!Method::of($name, $this)->assign($value) && property_exists($this, $name)) {
40
            $this->{$name} = $value;
41
        }
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getClassName(): string
48
    {
49
        static $name = null;
50
        if ($name === null) {
51
            $name = string(static::class)->lastSegment('\\');
52
        }
53
54
        return $name;
55
    }
56
}