4
4
5
5
use Faker \Generator as FakerGenerator ;
6
6
use PhpParser \Node ;
7
+ use PhpParser \Node \Expr \ClassConstFetch ;
8
+ use PhpParser \Node \Expr \Variable ;
9
+ use PhpParser \Node \Identifier ;
7
10
use PhpParser \Node \Scalar \String_ ;
8
11
use PhpParser \Node \Stmt ;
9
12
use PhpParser \Node \Stmt \Class_ ;
10
13
use PhpParser \Node \Stmt \ClassMethod ;
11
14
use PhpParser \Node \Stmt \Property ;
15
+ use PhpParser \Node \Stmt \PropertyProperty ;
16
+ use PhpParser \Node \VarLikeIdentifier ;
12
17
use PhpParser \NodeFinder ;
13
18
use PhpParser \Parser ;
14
19
use PhpSchool \PhpWorkshop \Check \FileComparisonCheck ;
@@ -68,7 +73,7 @@ public function getInitialCode(): SolutionInterface
68
73
public function getSolution (): SolutionInterface
69
74
{
70
75
return DirectorySolution::fromDirectory (
71
- realpath (__DIR__ . '/../../exercises/the-attributes-of-success/solution ' ),
76
+ ( string ) realpath (__DIR__ . '/../../exercises/the-attributes-of-success/solution ' ),
72
77
);
73
78
}
74
79
@@ -80,16 +85,18 @@ public function getType(): ExerciseType
80
85
public function getArgs (): array
81
86
{
82
87
return [
83
- json_encode (
84
- [
85
- 'id ' => random_int (0 , 100 ),
86
- 'comment ' => $ this ->faker ->sentence (4 ),
87
- 'rating ' => $ this ->faker ->numberBetween (0 , 5 ),
88
- 'reviewer ' => $ this ->faker ->userName (),
89
- 'date ' => $ this ->faker ->date ('d-m-Y ' )
90
- ],
91
- JSON_THROW_ON_ERROR
92
- )
88
+ [
89
+ json_encode (
90
+ [
91
+ 'id ' => random_int (0 , 100 ),
92
+ 'comment ' => $ this ->faker ->sentence (4 ),
93
+ 'rating ' => $ this ->faker ->numberBetween (0 , 5 ),
94
+ 'reviewer ' => $ this ->faker ->userName (),
95
+ 'date ' => $ this ->faker ->date ('d-m-Y ' )
96
+ ],
97
+ JSON_THROW_ON_ERROR
98
+ )
99
+ ]
93
100
];
94
101
}
95
102
@@ -157,10 +164,14 @@ public function check(Input $input): ResultInterface
157
164
return new Failure ($ this ->getName (), 'No flags were passed to Obfuscate Attribute definition ' );
158
165
}
159
166
160
- /** @var \PhpParser\Node\Expr\ ClassConstFetch $value */
167
+ /** @var ClassConstFetch $value */
161
168
$ value = $ attribute ->args [0 ]->value ;
162
169
163
- if ($ value ->class ->toString () !== 'Attribute ' || $ value ->name ->name !== 'TARGET_METHOD ' ) {
170
+ if (
171
+ $ value ->class ->toString () !== 'Attribute '
172
+ || !$ value ->name instanceof Identifier
173
+ || $ value ->name ->name !== 'TARGET_METHOD '
174
+ ) {
164
175
return new Failure (
165
176
$ this ->getName (),
166
177
'The Obfuscate Attribute was not configured as Attribute::TARGET_METHOD '
@@ -170,10 +181,10 @@ public function check(Input $input): ResultInterface
170
181
$ prop = (new NodeFinder ())->findFirst ($ attributeClass ->getProperties (), function (Node $ node ) {
171
182
return $ node instanceof Property
172
183
&& $ node ->isPublic ()
173
- && $ node ->type instanceof \ PhpParser \ Node \ Identifier
184
+ && $ node ->type instanceof Identifier
174
185
&& $ node ->type ->name === 'string '
175
- && $ node ->props [0 ] instanceof \ PhpParser \ Node \ Stmt \ PropertyProperty
176
- && $ node ->props [0 ]->name instanceof \ PhpParser \ Node \ VarLikeIdentifier
186
+ && $ node ->props [0 ] instanceof PropertyProperty
187
+ && $ node ->props [0 ]->name instanceof VarLikeIdentifier
177
188
&& $ node ->props [0 ]->name ->name === 'key ' ;
178
189
});
179
190
@@ -182,8 +193,9 @@ public function check(Input $input): ResultInterface
182
193
&& $ node ->name ->name === '__construct '
183
194
&& isset ($ node ->params [0 ])
184
195
&& $ node ->params [0 ]->flags === 1
196
+ && $ node ->params [0 ]->var instanceof Variable
185
197
&& $ node ->params [0 ]->var ->name === 'key '
186
- && $ node ->params [0 ]->type instanceof \ PhpParser \ Node \ Identifier
198
+ && $ node ->params [0 ]->type instanceof Identifier
187
199
&& $ node ->params [0 ]->type ->name === 'string ' ;
188
200
});
189
201
0 commit comments