@@ -76,7 +76,7 @@ final class BCFile
76
76
*
77
77
* Changelog for the PHPCS native function:
78
78
* - Introduced in PHPCS 0.0.5.
79
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
79
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
80
80
*
81
81
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
82
82
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
@@ -228,7 +228,9 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
228
228
// it's likely to be an array which might have arguments in it. This
229
229
// could cause problems in our parsing below, so lets just skip to the
230
230
// end of it.
231
- if (isset ($ tokens [$ i ]['parenthesis_opener ' ]) === true ) {
231
+ if ($ tokens [$ i ]['code ' ] !== T_TYPE_OPEN_PARENTHESIS
232
+ && isset ($ tokens [$ i ]['parenthesis_opener ' ]) === true
233
+ ) {
232
234
// Don't do this if it's the close parenthesis for the method.
233
235
if ($ i !== $ tokens [$ i ]['parenthesis_closer ' ]) {
234
236
$ i = ($ tokens [$ i ]['parenthesis_closer ' ] + 1 );
@@ -324,6 +326,8 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
324
326
case T_NS_SEPARATOR :
325
327
case T_TYPE_UNION :
326
328
case T_TYPE_INTERSECTION :
329
+ case T_TYPE_OPEN_PARENTHESIS :
330
+ case T_TYPE_CLOSE_PARENTHESIS :
327
331
case T_FALSE :
328
332
case T_TRUE :
329
333
case T_NULL :
@@ -462,7 +466,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
462
466
*
463
467
* Changelog for the PHPCS native function:
464
468
* - Introduced in PHPCS 0.0.5.
465
- * - PHPCS 3.9.2: skip over closure use statements. PHPCS #421 .
469
+ * - The upstream method has received no significant updates since PHPCS 3.10.0 .
466
470
*
467
471
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
468
472
* @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version.
@@ -480,147 +484,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
480
484
*/
481
485
public static function getMethodProperties (File $ phpcsFile , $ stackPtr )
482
486
{
483
- $ tokens = $ phpcsFile ->getTokens ();
484
-
485
- if ($ tokens [$ stackPtr ]['code ' ] !== T_FUNCTION
486
- && $ tokens [$ stackPtr ]['code ' ] !== T_CLOSURE
487
- && $ tokens [$ stackPtr ]['code ' ] !== T_FN
488
- ) {
489
- throw new RuntimeException ('$stackPtr must be of type T_FUNCTION or T_CLOSURE or T_FN ' );
490
- }
491
-
492
- if ($ tokens [$ stackPtr ]['code ' ] === T_FUNCTION ) {
493
- $ valid = [
494
- T_PUBLIC => T_PUBLIC ,
495
- T_PRIVATE => T_PRIVATE ,
496
- T_PROTECTED => T_PROTECTED ,
497
- T_STATIC => T_STATIC ,
498
- T_FINAL => T_FINAL ,
499
- T_ABSTRACT => T_ABSTRACT ,
500
- T_WHITESPACE => T_WHITESPACE ,
501
- T_COMMENT => T_COMMENT ,
502
- T_DOC_COMMENT => T_DOC_COMMENT ,
503
- ];
504
- } else {
505
- $ valid = [
506
- T_STATIC => T_STATIC ,
507
- T_WHITESPACE => T_WHITESPACE ,
508
- T_COMMENT => T_COMMENT ,
509
- T_DOC_COMMENT => T_DOC_COMMENT ,
510
- ];
511
- }
512
-
513
- $ scope = 'public ' ;
514
- $ scopeSpecified = false ;
515
- $ isAbstract = false ;
516
- $ isFinal = false ;
517
- $ isStatic = false ;
518
-
519
- for ($ i = ($ stackPtr - 1 ); $ i > 0 ; $ i --) {
520
- if (isset ($ valid [$ tokens [$ i ]['code ' ]]) === false ) {
521
- break ;
522
- }
523
-
524
- switch ($ tokens [$ i ]['code ' ]) {
525
- case T_PUBLIC :
526
- $ scope = 'public ' ;
527
- $ scopeSpecified = true ;
528
- break ;
529
- case T_PRIVATE :
530
- $ scope = 'private ' ;
531
- $ scopeSpecified = true ;
532
- break ;
533
- case T_PROTECTED :
534
- $ scope = 'protected ' ;
535
- $ scopeSpecified = true ;
536
- break ;
537
- case T_ABSTRACT :
538
- $ isAbstract = true ;
539
- break ;
540
- case T_FINAL :
541
- $ isFinal = true ;
542
- break ;
543
- case T_STATIC :
544
- $ isStatic = true ;
545
- break ;
546
- }
547
- }
548
-
549
- $ returnType = '' ;
550
- $ returnTypeToken = false ;
551
- $ returnTypeEndToken = false ;
552
- $ nullableReturnType = false ;
553
- $ hasBody = true ;
554
- $ returnTypeTokens = Collections::returnTypeTokens ();
555
-
556
- if (isset ($ tokens [$ stackPtr ]['parenthesis_closer ' ]) === true ) {
557
- $ scopeOpener = null ;
558
- if (isset ($ tokens [$ stackPtr ]['scope_opener ' ]) === true ) {
559
- $ scopeOpener = $ tokens [$ stackPtr ]['scope_opener ' ];
560
- }
561
-
562
- for ($ i = $ tokens [$ stackPtr ]['parenthesis_closer ' ]; $ i < $ phpcsFile ->numTokens ; $ i ++) {
563
- if (($ scopeOpener === null && $ tokens [$ i ]['code ' ] === T_SEMICOLON )
564
- || ($ scopeOpener !== null && $ i === $ scopeOpener )
565
- ) {
566
- // End of function definition.
567
- break ;
568
- }
569
-
570
- if ($ tokens [$ i ]['code ' ] === T_USE ) {
571
- // Skip over closure use statements.
572
- for ($ j = ($ i + 1 ); $ j < $ phpcsFile ->numTokens && isset (Tokens::$ emptyTokens [$ tokens [$ j ]['code ' ]]) === true ; $ j ++);
573
- if ($ tokens [$ j ]['code ' ] === T_OPEN_PARENTHESIS ) {
574
- if (isset ($ tokens [$ j ]['parenthesis_closer ' ]) === false ) {
575
- // Live coding/parse error, stop parsing.
576
- break ;
577
- }
578
-
579
- $ i = $ tokens [$ j ]['parenthesis_closer ' ];
580
- continue ;
581
- }
582
- }
583
-
584
- if ($ tokens [$ i ]['code ' ] === T_NULLABLE ) {
585
- $ nullableReturnType = true ;
586
- }
587
-
588
- if (isset ($ returnTypeTokens [$ tokens [$ i ]['code ' ]]) === true ) {
589
- if ($ returnTypeToken === false ) {
590
- $ returnTypeToken = $ i ;
591
- }
592
-
593
- $ returnType .= $ tokens [$ i ]['content ' ];
594
- $ returnTypeEndToken = $ i ;
595
- }
596
- }
597
-
598
- if ($ tokens [$ stackPtr ]['code ' ] === T_FN ) {
599
- $ bodyToken = T_FN_ARROW ;
600
- } else {
601
- $ bodyToken = T_OPEN_CURLY_BRACKET ;
602
- }
603
-
604
- $ end = $ phpcsFile ->findNext ([$ bodyToken , T_SEMICOLON ], $ tokens [$ stackPtr ]['parenthesis_closer ' ]);
605
- $ hasBody = ($ end !== false && $ tokens [$ end ]['code ' ] === $ bodyToken );
606
- }
607
-
608
- if ($ returnType !== '' && $ nullableReturnType === true ) {
609
- $ returnType = '? ' . $ returnType ;
610
- }
611
-
612
- return [
613
- 'scope ' => $ scope ,
614
- 'scope_specified ' => $ scopeSpecified ,
615
- 'return_type ' => $ returnType ,
616
- 'return_type_token ' => $ returnTypeToken ,
617
- 'return_type_end_token ' => $ returnTypeEndToken ,
618
- 'nullable_return_type ' => $ nullableReturnType ,
619
- 'is_abstract ' => $ isAbstract ,
620
- 'is_final ' => $ isFinal ,
621
- 'is_static ' => $ isStatic ,
622
- 'has_body ' => $ hasBody ,
623
- ];
487
+ return $ phpcsFile ->getMethodProperties ($ stackPtr );
624
488
}
625
489
626
490
/**
@@ -647,7 +511,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
647
511
*
648
512
* Changelog for the PHPCS native function:
649
513
* - Introduced in PHPCS 0.0.5.
650
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
514
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
651
515
*
652
516
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
653
517
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
@@ -685,7 +549,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
685
549
*
686
550
* Changelog for the PHPCS native function:
687
551
* - Introduced in PHPCS 1.3.0.
688
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
552
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
689
553
*
690
554
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
691
555
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.
@@ -713,7 +577,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
713
577
*
714
578
* Changelog for the PHPCS native function:
715
579
* - Introduced in PHPCS 0.0.5.
716
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
580
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
717
581
*
718
582
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
719
583
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
@@ -739,7 +603,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
739
603
*
740
604
* Changelog for the PHPCS native function:
741
605
* - Introduced in PHPCS 0.0.5.
742
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
606
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
743
607
*
744
608
* @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source.
745
609
* @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions.
@@ -768,7 +632,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig
768
632
*
769
633
* Changelog for the PHPCS native function:
770
634
* - Introduced in PHPCS 2.1.0.
771
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
635
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
772
636
*
773
637
* @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source.
774
638
*
@@ -792,7 +656,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n
792
656
*
793
657
* Changelog for the PHPCS native function:
794
658
* - Introduced in PHPCS 2.1.0.
795
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
659
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
796
660
*
797
661
* @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source.
798
662
*
@@ -816,7 +680,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul
816
680
*
817
681
* Changelog for the PHPCS native function:
818
682
* - Introduced in PHPCS 0.0.5.
819
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
683
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
820
684
*
821
685
* @see \PHP_CodeSniffer\Files\File::hasCondition() Original source.
822
686
* @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative.
@@ -841,7 +705,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types)
841
705
*
842
706
* Changelog for the PHPCS native function:
843
707
* - Introduced in PHPCS 1.3.0.
844
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
708
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
845
709
*
846
710
* @see \PHP_CodeSniffer\Files\File::getCondition() Original source.
847
711
* @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative.
@@ -872,7 +736,7 @@ public static function getCondition(File $phpcsFile, $stackPtr, $type, $first =
872
736
*
873
737
* Changelog for the PHPCS native function:
874
738
* - Introduced in PHPCS 1.2.0.
875
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
739
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
876
740
*
877
741
* @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source.
878
742
* @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version.
@@ -897,7 +761,7 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr)
897
761
*
898
762
* Changelog for the PHPCS native function:
899
763
* - Introduced in PHPCS 2.7.0.
900
- * - The upstream method has received no significant updates since PHPCS 3.9 .0.
764
+ * - The upstream method has received no significant updates since PHPCS 3.10 .0.
901
765
*
902
766
* @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source.
903
767
* @see \PHPCSUtils\Utils\ObjectDeclarations::findImplementedInterfaceNames() PHPCSUtils native improved version.
0 commit comments