@@ -40,28 +40,29 @@ public function __construct(
40
40
public function findTargetClasses (string $ attribute ): array
41
41
{
42
42
return array_map (
43
- fn (array $ a ) => new TargetClass ( self ::createClassAttribute ($ attribute , ...$ a ), $ a [ 1 ] ),
44
- $ this ->targetClasses [$ attribute ] ?? []
43
+ fn (array $ t ) => self ::createClassAttribute ($ attribute , ...$ t ),
44
+ $ this ->targetClasses [$ attribute ] ?? [],
45
45
);
46
46
}
47
47
48
48
/**
49
49
* @template T of object
50
50
*
51
51
* @param class-string<T> $attribute
52
- * @param array<int|string, mixed> $arguments
52
+ * @param array<mixed> $arguments
53
53
* @param class-string $class
54
54
*
55
- * @return T
55
+ * @return TargetClass<T>
56
56
*/
57
57
private static function createClassAttribute (string $ attribute , array $ arguments , string $ class ): object
58
58
{
59
59
try {
60
- return new $ attribute (...$ arguments );
60
+ $ a = new $ attribute (...$ arguments );
61
+ return new TargetClass ($ a , $ class );
61
62
} catch (Throwable $ e ) {
62
63
throw new RuntimeException (
63
64
"An error occurred while instantiating attribute $ attribute on class $ class " ,
64
- previous: $ e
65
+ previous: $ e,
65
66
);
66
67
}
67
68
}
@@ -76,32 +77,34 @@ private static function createClassAttribute(string $attribute, array $arguments
76
77
public function findTargetMethods (string $ attribute ): array
77
78
{
78
79
return array_map (
79
- fn (array $ a ) => new TargetMethod ( self ::createMethodAttribute ($ attribute , ...$ a ), $ a [ 1 ], $ a [ 2 ] ),
80
- $ this ->targetMethods [$ attribute ] ?? []
80
+ fn (array $ t ) => self ::createMethodAttribute ($ attribute , ...$ t ),
81
+ $ this ->targetMethods [$ attribute ] ?? [],
81
82
);
82
83
}
83
84
84
85
/**
85
86
* @template T of object
86
87
*
87
88
* @param class-string<T> $attribute
88
- * @param array<int|string, mixed> $arguments
89
+ * @param array<mixed> $arguments
89
90
* @param class-string $class
91
+ * @param non-empty-string $method
90
92
*
91
- * @return T
93
+ * @return TargetMethod<T>
92
94
*/
93
95
private static function createMethodAttribute (
94
96
string $ attribute ,
95
97
array $ arguments ,
96
98
string $ class ,
97
- string $ method
99
+ string $ method,
98
100
): object {
99
101
try {
100
- return new $ attribute (...$ arguments );
102
+ $ a = new $ attribute (...$ arguments );
103
+ return new TargetMethod ($ a , $ class , $ method );
101
104
} catch (Throwable $ e ) {
102
105
throw new RuntimeException (
103
106
"An error occurred while instantiating attribute $ attribute on method $ class:: $ method " ,
104
- previous: $ e
107
+ previous: $ e,
105
108
);
106
109
}
107
110
}
@@ -116,32 +119,34 @@ private static function createMethodAttribute(
116
119
public function findTargetProperties (string $ attribute ): array
117
120
{
118
121
return array_map (
119
- fn (array $ a ) => new TargetProperty ( self ::createPropertyAttribute ($ attribute , ...$ a ), $ a [ 1 ], $ a [ 2 ] ),
120
- $ this ->targetProperties [$ attribute ] ?? []
122
+ fn (array $ t ) => self ::createPropertyAttribute ($ attribute , ...$ t ),
123
+ $ this ->targetProperties [$ attribute ] ?? [],
121
124
);
122
125
}
123
126
124
127
/**
125
128
* @template T of object
126
129
*
127
130
* @param class-string<T> $attribute
128
- * @param array<int|string, mixed> $arguments
131
+ * @param array<mixed> $arguments
129
132
* @param class-string $class
133
+ * @param non-empty-string $property
130
134
*
131
- * @return T
135
+ * @return TargetProperty<T>
132
136
*/
133
137
private static function createPropertyAttribute (
134
138
string $ attribute ,
135
139
array $ arguments ,
136
140
string $ class ,
137
- string $ property
141
+ string $ property,
138
142
): object {
139
143
try {
140
- return new $ attribute (...$ arguments );
144
+ $ a = new $ attribute (...$ arguments );
145
+ return new TargetProperty ($ a , $ class , $ property );
141
146
} catch (Throwable $ e ) {
142
147
throw new RuntimeException (
143
148
"An error occurred while instantiating attribute $ attribute on property $ class:: $ property " ,
144
- previous: $ e
149
+ previous: $ e,
145
150
);
146
151
}
147
152
}
@@ -156,9 +161,9 @@ public function filterTargetClasses(callable $predicate): array
156
161
$ ar = [];
157
162
158
163
foreach ($ this ->targetClasses as $ attribute => $ references ) {
159
- foreach ($ references as [ $ arguments , $ class ]) {
164
+ foreach ($ references as [$ arguments , $ class ]) {
160
165
if ($ predicate ($ attribute , $ class )) {
161
- $ ar [] = new TargetClass ( self ::createClassAttribute ($ attribute , $ arguments, $ class ) , $ class );
166
+ $ ar [] = self ::createClassAttribute ($ attribute , $ arguments , $ class );
162
167
}
163
168
}
164
169
}
@@ -176,14 +181,14 @@ public function filterTargetMethods(callable $predicate): array
176
181
$ ar = [];
177
182
178
183
foreach ($ this ->targetMethods as $ attribute => $ references ) {
179
- foreach ($ references as [ $ arguments , $ class , $ method ]) {
184
+ foreach ($ references as [$ arguments , $ class , $ method ]) {
180
185
if ($ predicate ($ attribute , $ class , $ method )) {
181
- $ ar [] = new TargetMethod ( self ::createMethodAttribute (
186
+ $ ar [] = self ::createMethodAttribute (
182
187
$ attribute ,
183
188
$ arguments ,
184
189
$ class ,
185
- $ method
186
- ), $ class , $ method ) ;
190
+ $ method,
191
+ );
187
192
}
188
193
}
189
194
}
@@ -201,14 +206,14 @@ public function filterTargetProperties(callable $predicate): array
201
206
$ ar = [];
202
207
203
208
foreach ($ this ->targetProperties as $ attribute => $ references ) {
204
- foreach ($ references as [ $ arguments , $ class , $ property ]) {
209
+ foreach ($ references as [$ arguments , $ class , $ property ]) {
205
210
if ($ predicate ($ attribute , $ class , $ property )) {
206
- $ ar [] = new TargetProperty ( self ::createPropertyAttribute (
211
+ $ ar [] = self ::createPropertyAttribute (
207
212
$ attribute ,
208
213
$ arguments ,
209
214
$ class ,
210
- $ property
211
- ), $ class , $ property ) ;
215
+ $ property,
216
+ );
212
217
}
213
218
}
214
219
}
0 commit comments