44
55use Faker \Generator as FakerGenerator ;
66use PhpParser \Node ;
7+ use PhpParser \Node \Expr \ClassConstFetch ;
8+ use PhpParser \Node \Expr \Variable ;
9+ use PhpParser \Node \Identifier ;
710use PhpParser \Node \Scalar \String_ ;
811use PhpParser \Node \Stmt ;
912use PhpParser \Node \Stmt \Class_ ;
1013use PhpParser \Node \Stmt \ClassMethod ;
1114use PhpParser \Node \Stmt \Property ;
15+ use PhpParser \Node \Stmt \PropertyProperty ;
16+ use PhpParser \Node \VarLikeIdentifier ;
1217use PhpParser \NodeFinder ;
1318use PhpParser \Parser ;
1419use PhpSchool \PhpWorkshop \Check \FileComparisonCheck ;
@@ -68,7 +73,7 @@ public function getInitialCode(): SolutionInterface
6873 public function getSolution (): SolutionInterface
6974 {
7075 return DirectorySolution::fromDirectory (
71- realpath (__DIR__ . '/../../exercises/the-attributes-of-success/solution ' ),
76+ ( string ) realpath (__DIR__ . '/../../exercises/the-attributes-of-success/solution ' ),
7277 );
7378 }
7479
@@ -80,16 +85,18 @@ public function getType(): ExerciseType
8085 public function getArgs (): array
8186 {
8287 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+ ]
93100 ];
94101 }
95102
@@ -157,10 +164,14 @@ public function check(Input $input): ResultInterface
157164 return new Failure ($ this ->getName (), 'No flags were passed to Obfuscate Attribute definition ' );
158165 }
159166
160- /** @var \PhpParser\Node\Expr\ ClassConstFetch $value */
167+ /** @var ClassConstFetch $value */
161168 $ value = $ attribute ->args [0 ]->value ;
162169
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+ ) {
164175 return new Failure (
165176 $ this ->getName (),
166177 'The Obfuscate Attribute was not configured as Attribute::TARGET_METHOD '
@@ -170,10 +181,10 @@ public function check(Input $input): ResultInterface
170181 $ prop = (new NodeFinder ())->findFirst ($ attributeClass ->getProperties (), function (Node $ node ) {
171182 return $ node instanceof Property
172183 && $ node ->isPublic ()
173- && $ node ->type instanceof \ PhpParser \ Node \ Identifier
184+ && $ node ->type instanceof Identifier
174185 && $ 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
177188 && $ node ->props [0 ]->name ->name === 'key ' ;
178189 });
179190
@@ -182,8 +193,9 @@ public function check(Input $input): ResultInterface
182193 && $ node ->name ->name === '__construct '
183194 && isset ($ node ->params [0 ])
184195 && $ node ->params [0 ]->flags === 1
196+ && $ node ->params [0 ]->var instanceof Variable
185197 && $ node ->params [0 ]->var ->name === 'key '
186- && $ node ->params [0 ]->type instanceof \ PhpParser \ Node \ Identifier
198+ && $ node ->params [0 ]->type instanceof Identifier
187199 && $ node ->params [0 ]->type ->name === 'string ' ;
188200 });
189201
0 commit comments