9
9
*/
10
10
namespace Phpbb \Epv \Tests \Tests ;
11
11
12
-
13
12
use Phpbb \Epv \Files \FileInterface ;
14
13
use Phpbb \Epv \Files \Type \LangFileInterface ;
15
14
use Phpbb \Epv \Files \Type \PHPFileInterface ;
29
28
use PhpParser \Node \Expr \Print_ ;
30
29
use PhpParser \Node \Expr \PropertyFetch ;
31
30
use PhpParser \Node \Expr \Variable ;
31
+ use PhpParser \Node \Name ;
32
32
use PhpParser \Node \Scalar \String_ ;
33
33
use PhpParser \Node \Stmt \Class_ ;
34
34
use PhpParser \Node \Stmt \Declare_ ;
@@ -333,7 +333,11 @@ private function checkInDefined(If_ $node)
333
333
{
334
334
$ cond = $ node ->cond ;
335
335
336
- if ($ cond instanceof BooleanNot && $ cond ->expr instanceof FuncCall && $ cond ->expr ->name ->parts [0 ] == 'defined ' && $ cond ->expr ->args [0 ]->value ->value == 'IN_PHPBB ' )
336
+ if ($ cond instanceof BooleanNot
337
+ && $ cond ->expr instanceof FuncCall
338
+ && $ cond ->expr ->name ->getFirst () === 'defined '
339
+ && $ cond ->expr ->args [0 ]->value ->value === 'IN_PHPBB '
340
+ )
337
341
{
338
342
339
343
if ($ node ->stmts [0 ]->expr instanceof Node \Expr \Exit_)
@@ -369,9 +373,9 @@ private function validateFunctionNames(Node $node)
369
373
{
370
374
$ name = $ this ->getMethodName ($ node );
371
375
}
372
- else if (isset ($ node ->expr ) && $ node ->expr instanceof FuncCall && isset ( $ node ->expr ->name -> parts ) && is_array ( $ node -> expr -> name -> parts ) )
376
+ else if (isset ($ node ->expr ) && $ node ->expr instanceof FuncCall && $ node ->expr ->name instanceof Name )
373
377
{
374
- $ name = ( string ) $ node ->expr ->name ->parts [ 0 ] ;
378
+ $ name = $ node ->expr ->name ->getFirst () ;
375
379
}
376
380
377
381
if ($ name !== null )
@@ -393,9 +397,17 @@ private function validateMethodCalls(Node $node) {
393
397
{
394
398
$ name = $ this ->getMethodName ($ node );
395
399
}
396
- else if (isset ($ node ->expr ) && $ node ->expr instanceof Node \Expr \MethodCall && !($ node ->expr ->name instanceof Variable) && !($ node ->expr ->name instanceof PropertyFetch) && !($ node ->expr ->name instanceof Concat))
400
+ else if (isset ($ node ->expr )
401
+ && $ node ->expr instanceof Node \Expr \MethodCall
402
+ && !($ node ->expr ->name instanceof Variable
403
+ || $ node ->expr ->name instanceof PropertyFetch
404
+ || $ node ->expr ->name instanceof Concat
405
+ || $ node ->expr ->name instanceof Node \Scalar \Encapsed
406
+ || $ node ->expr ->name instanceof Node \Expr \Ternary
407
+ )
408
+ )
397
409
{
398
- $ name = ( string ) $ node ->expr ->name ;
410
+ $ name = $ node ->expr ->name -> toString () ;
399
411
}
400
412
401
413
if ($ name !== null )
@@ -414,21 +426,62 @@ private function getMethodName(Node $node)
414
426
{
415
427
return null ; // This is a variable. We are going to ignore this. We do not want to track variable contents
416
428
}
417
- else if ($ node ->name instanceof Concat)
418
- {
419
- // Only test if both are a string
420
- // This mean that if a user works around this test he can do so, but otherwise we will
421
- // need to parse variables and stuff.
422
- if ($ node ->name ->left instanceof String_ && $ node ->name ->right instanceof String_)
423
- {
424
- return $ node ->name ->left ->value . $ node ->name ->right ->value ;
425
- }
426
- }
427
- else
428
- {
429
- return (string )$ node ->name ;
430
- }
431
- return null ;
429
+
430
+ if ($ node ->name instanceof Concat)
431
+ {
432
+ // Only test if both are a string
433
+ // This mean that if a user works around this test he can do so, but otherwise we will
434
+ // need to parse variables and stuff.
435
+ if ($ node ->name ->left instanceof String_ && $ node ->name ->right instanceof String_)
436
+ {
437
+ return $ node ->name ->left ->value . $ node ->name ->right ->value ;
438
+ }
439
+ }
440
+ else if ($ node ->name instanceof Expr \Ternary)
441
+ {
442
+ return $ node ->name ->if ;
443
+ }
444
+ else if ($ node ->name instanceof Node \Scalar \Encapsed)
445
+ {
446
+ $ encapsed = '' ;
447
+ foreach ($ node ->name ->parts as $ part )
448
+ {
449
+ if ($ part instanceof Node \Scalar \EncapsedStringPart)
450
+ {
451
+ $ encapsed .= $ part ->value ;
452
+ }
453
+ else if ($ part instanceof Variable)
454
+ {
455
+ $ encapsed .= $ part ->name ;
456
+ }
457
+ else if ($ part instanceof PropertyFetch)
458
+ {
459
+ $ encapsed .= $ part ->name ->name ;
460
+ }
461
+ else if ($ part instanceof ArrayDimFetch)
462
+ {
463
+ $ encapsed .= $ part ->var ->name ;
464
+ }
465
+ else
466
+ {
467
+ $ encapsed .= $ part ->toString ();
468
+ }
469
+ }
470
+ return $ encapsed ?: null ;
471
+ }
472
+ else if ($ node ->name instanceof Node \Identifier)
473
+ {
474
+ return $ node ->name ->name ;
475
+ }
476
+ else if ($ node ->name instanceof Node \Name)
477
+ {
478
+ return $ node ->name ->getFirst ();
479
+ }
480
+ else
481
+ {
482
+ return $ node ->name ->toString ();
483
+ }
484
+ return null ;
432
485
}
433
486
434
487
/**
0 commit comments