1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Spiral Framework. Cycle ProxyFactory |
5
|
|
|
* |
6
|
|
|
* @license MIT |
7
|
|
|
* @author Valentin V (Vvval) |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Cycle\ORM\Promise\Declaration; |
13
|
|
|
|
14
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
15
|
|
|
|
16
|
|
|
final class Structure |
17
|
|
|
{ |
18
|
|
|
/** @var string[] */ |
19
|
|
|
public $constants = []; |
20
|
|
|
|
21
|
|
|
/** @var ClassMethod[] */ |
22
|
|
|
public $methods = []; |
23
|
|
|
|
24
|
|
|
/** @var bool */ |
25
|
|
|
public $hasClone; |
26
|
|
|
|
27
|
|
|
/** @var \SplObjectStorage */ |
28
|
|
|
private $properties; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Structure constructor. |
32
|
|
|
*/ |
33
|
|
|
protected function __construct() |
34
|
|
|
{ |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $constants |
39
|
|
|
* @param \SplObjectStorage $properties |
40
|
|
|
* @param bool $hasClone |
41
|
|
|
* @param ClassMethod ...$methods |
42
|
|
|
* @return Structure |
43
|
|
|
*/ |
44
|
|
|
public static function create( |
45
|
|
|
array $constants, |
46
|
|
|
\SplObjectStorage $properties, |
47
|
|
|
bool $hasClone, |
48
|
|
|
ClassMethod ...$methods |
49
|
|
|
): Structure { |
50
|
|
|
$self = new self(); |
51
|
|
|
$self->constants = $constants; |
52
|
|
|
$self->properties = $properties; |
53
|
|
|
$self->methods = $methods; |
54
|
|
|
$self->hasClone = $hasClone; |
55
|
|
|
|
56
|
|
|
return $self; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string[] |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function toBeUnsetProperties(): array |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$names = []; |
65
|
|
|
/** @var \ReflectionProperty $property */ |
66
|
|
|
foreach ($this->properties as $property) { |
67
|
|
|
if ($this->properties[$property] === true && $property->isPublic()) { |
68
|
|
|
$names[] = $property->getName(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $names; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string[] |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
public function publicProperties(): array |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$names = []; |
81
|
|
|
/** @var \ReflectionProperty $property */ |
82
|
|
|
foreach ($this->properties as $property) { |
83
|
|
|
if ($property->isPublic()) { |
84
|
|
|
$names[] = $property->getName(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $names; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string[] |
93
|
|
|
*/ |
94
|
|
|
public function properties(): array |
95
|
|
|
{ |
96
|
|
|
$names = []; |
97
|
|
|
/** @var \ReflectionProperty $property */ |
98
|
|
|
foreach ($this->properties as $property) { |
99
|
|
|
$names[] = $property->getName(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $names; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function methodNames(): array |
109
|
|
|
{ |
110
|
|
|
$names = []; |
111
|
|
|
foreach ($this->methods as $method) { |
112
|
|
|
$names[] = $method->name->name; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $names; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.