Completed
Push — master ( ba2e48...30eea4 )
by Randy
02:38
created

Hydrate::setValueWithVariantNames()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A Hydrate::getClassName() 0 4 1
1
<?php
2
3
namespace Dgame\Soap\Hydrator;
4
5
use Dgame\Object\ObjectFacade;
6
use Dgame\Soap\AssignableInterface;
7
8
/**
9
 * Class Hydrate
10
 * @package Dgame\Soap\Hydrator
11
 */
12
final class Hydrate extends ObjectFacade
13
{
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
19
    /**
20
     * Hydrate constructor.
21
     *
22
     * @param string $name
23
     * @param string $class
24
     */
25 9
    public function __construct(string $name, string $class)
26
    {
27 9
        parent::__construct(new $class());
28
29 9
        $this->name = $name;
30 9
    }
31
32
    /**
33
     * @param string $name
34
     * @param string $class
35
     *
36
     * @return Hydrate
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
37
     */
38 9
    public static function new(string $name, string $class): self
39
    {
40 9
        return new self($name, $class);
41
    }
42
43
    /**
44
     * @param Hydrate $hydrate
0 ignored issues
show
Documentation introduced by
Should the type for parameter $hydrate not be \self?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
45
     *
46
     * @return bool
47
     */
48 5
    public function append(self $hydrate): bool
49
    {
50 5
        foreach ([$hydrate->getName(), $hydrate->getClassName()] as $name) {
51 5
            if ($this->setValue($name, $hydrate->getObject())) {
52 5
                return true;
53
            }
54
        }
55
56
        return false;
57
    }
58
59
    /**
60
     * @param AssignableInterface $assignable
61
     *
62
     * @return bool
63
     */
64 8
    public function assign(AssignableInterface $assignable): bool
65
    {
66 8
        if ($assignable->hasValue()) {
67 8
            return $this->setValue($assignable->getName(), $assignable->getValue());
68
        }
69
70 1
        return false;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 5
    public function getClassName(): string
77
    {
78 5
        return $this->getReflection()->getShortName();
79
    }
80
81
    /**
82
     * @return string
83
     */
84 5
    public function getName(): string
85
    {
86 5
        return $this->name;
87
    }
88
}