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

Hydratable   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 8
lcom 0
cbo 4
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A assign() 0 6 2
A append() 0 4 1
A assignValue() 0 6 3
A getClassName() 0 9 2
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
}