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 |
|
|
|
|
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 |
|
|
|
|
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
5 |
|
public function append(self $hydrate): bool |
49
|
|
|
{ |
50
|
5 |
|
return $this->setValueWithVariantNames([$hydrate->getName(), $hydrate->getClassName()], $hydrate->getObject()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param AssignableInterface $assignable |
55
|
|
|
* |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
8 |
|
public function assign(AssignableInterface $assignable): bool |
59
|
|
|
{ |
60
|
8 |
|
if ($assignable->hasValue()) { |
61
|
8 |
|
return $this->setValueWithVariantNames([$assignable->getName()], $assignable->getValue()); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array $names |
69
|
|
|
* @param $value |
70
|
|
|
* |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
9 |
|
private function setValueWithVariantNames(array $names, $value) |
74
|
|
|
{ |
75
|
9 |
|
foreach (self::getAppendNames($names) as $name) { |
76
|
9 |
|
if ($this->setValue($name, $value)) { |
77
|
9 |
|
return true; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
return false; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $names |
86
|
|
|
* |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
9 |
|
private static function getAppendNames(array $names): array |
90
|
|
|
{ |
91
|
9 |
|
$output = []; |
92
|
9 |
|
foreach ($names as $name) { |
93
|
9 |
|
$output[] = lcfirst($name); |
94
|
9 |
|
$output[] = ucfirst($name); |
95
|
|
|
} |
96
|
|
|
|
97
|
9 |
|
return $output; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
5 |
|
public function getClassName(): string |
104
|
|
|
{ |
105
|
5 |
|
return $this->getReflection()->getShortName(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
5 |
|
public function getName(): string |
112
|
|
|
{ |
113
|
5 |
|
return $this->name; |
114
|
|
|
} |
115
|
|
|
} |
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.