@@ -267,7 +267,7 @@ class File
267
267
*
268
268
* @return void
269
269
*/
270
- public function __construct ($ path , Ruleset $ ruleset , Config $ config )
270
+ public function __construct (string $ path , Ruleset $ ruleset , Config $ config )
271
271
{
272
272
$ this ->path = $ path ;
273
273
$ this ->ruleset = $ ruleset ;
@@ -296,7 +296,7 @@ public function __construct($path, Ruleset $ruleset, Config $config)
296
296
*
297
297
* @return void
298
298
*/
299
- public function setContent ($ content )
299
+ public function setContent (string $ content )
300
300
{
301
301
$ this ->content = $ content ;
302
302
$ this ->tokens = [];
@@ -671,12 +671,12 @@ public function cleanUp()
671
671
* @return boolean
672
672
*/
673
673
public function addError (
674
- $ error ,
675
- $ stackPtr ,
676
- $ code ,
677
- $ data =[],
678
- $ severity =0 ,
679
- $ fixable =false
674
+ string $ error ,
675
+ ? int $ stackPtr ,
676
+ string $ code ,
677
+ array $ data =[],
678
+ int $ severity =0 ,
679
+ bool $ fixable =false
680
680
) {
681
681
if ($ stackPtr === null ) {
682
682
$ line = 1 ;
@@ -705,12 +705,12 @@ public function addError(
705
705
* @return boolean
706
706
*/
707
707
public function addWarning (
708
- $ warning ,
709
- $ stackPtr ,
710
- $ code ,
711
- $ data =[],
712
- $ severity =0 ,
713
- $ fixable =false
708
+ string $ warning ,
709
+ ? int $ stackPtr ,
710
+ string $ code ,
711
+ array $ data =[],
712
+ int $ severity =0 ,
713
+ bool $ fixable =false
714
714
) {
715
715
if ($ stackPtr === null ) {
716
716
$ line = 1 ;
@@ -738,11 +738,11 @@ public function addWarning(
738
738
* @return boolean
739
739
*/
740
740
public function addErrorOnLine (
741
- $ error ,
742
- $ line ,
743
- $ code ,
744
- $ data =[],
745
- $ severity =0
741
+ string $ error ,
742
+ int $ line ,
743
+ string $ code ,
744
+ array $ data =[],
745
+ int $ severity =0
746
746
) {
747
747
return $ this ->addMessage (true , $ error , $ line , 1 , $ code , $ data , $ severity , false );
748
748
@@ -762,11 +762,11 @@ public function addErrorOnLine(
762
762
* @return boolean
763
763
*/
764
764
public function addWarningOnLine (
765
- $ warning ,
766
- $ line ,
767
- $ code ,
768
- $ data =[],
769
- $ severity =0
765
+ string $ warning ,
766
+ int $ line ,
767
+ string $ code ,
768
+ array $ data =[],
769
+ int $ severity =0
770
770
) {
771
771
return $ this ->addMessage (false , $ warning , $ line , 1 , $ code , $ data , $ severity , false );
772
772
@@ -788,11 +788,11 @@ public function addWarningOnLine(
788
788
* @return boolean
789
789
*/
790
790
public function addFixableError (
791
- $ error ,
792
- $ stackPtr ,
793
- $ code ,
794
- $ data =[],
795
- $ severity =0
791
+ string $ error ,
792
+ int $ stackPtr ,
793
+ string $ code ,
794
+ array $ data =[],
795
+ int $ severity =0
796
796
) {
797
797
$ recorded = $ this ->addError ($ error , $ stackPtr , $ code , $ data , $ severity , true );
798
798
if ($ recorded === true && $ this ->fixer ->enabled === true ) {
@@ -819,11 +819,11 @@ public function addFixableError(
819
819
* @return boolean
820
820
*/
821
821
public function addFixableWarning (
822
- $ warning ,
823
- $ stackPtr ,
824
- $ code ,
825
- $ data =[],
826
- $ severity =0
822
+ string $ warning ,
823
+ int $ stackPtr ,
824
+ string $ code ,
825
+ array $ data =[],
826
+ int $ severity =0
827
827
) {
828
828
$ recorded = $ this ->addWarning ($ warning , $ stackPtr , $ code , $ data , $ severity , true );
829
829
if ($ recorded === true && $ this ->fixer ->enabled === true ) {
@@ -850,8 +850,16 @@ public function addFixableWarning(
850
850
*
851
851
* @return boolean
852
852
*/
853
- protected function addMessage ($ error , $ message , $ line , $ column , $ code , $ data , $ severity , $ fixable )
854
- {
853
+ protected function addMessage (
854
+ bool $ error ,
855
+ string $ message ,
856
+ int $ line ,
857
+ int $ column ,
858
+ string $ code ,
859
+ array $ data ,
860
+ int $ severity ,
861
+ bool $ fixable
862
+ ) {
855
863
// Check if this line is ignoring all message codes.
856
864
if (isset ($ this ->tokenizer ->ignoredLines [$ line ]) === true && $ this ->tokenizer ->ignoredLines [$ line ]->ignoresEverything () === true ) {
857
865
return false ;
@@ -1097,7 +1105,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
1097
1105
*
1098
1106
* @return boolean
1099
1107
*/
1100
- public function recordMetric ($ stackPtr , $ metric , $ value )
1108
+ public function recordMetric (int $ stackPtr , string $ metric , string $ value )
1101
1109
{
1102
1110
if (isset ($ this ->metrics [$ metric ]) === false ) {
1103
1111
$ this ->metrics [$ metric ] = ['values ' => [$ value => 1 ]];
@@ -1311,7 +1319,7 @@ public function getFilename()
1311
1319
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
1312
1320
* T_FUNCTION, T_CLASS, T_TRAIT, T_ENUM, or T_INTERFACE.
1313
1321
*/
1314
- public function getDeclarationName ($ stackPtr )
1322
+ public function getDeclarationName (int $ stackPtr )
1315
1323
{
1316
1324
$ tokenCode = $ this ->tokens [$ stackPtr ]['code ' ];
1317
1325
@@ -1402,7 +1410,7 @@ public function getDeclarationName($stackPtr)
1402
1410
* type T_FUNCTION, T_CLOSURE, T_USE,
1403
1411
* or T_FN.
1404
1412
*/
1405
- public function getMethodParameters ($ stackPtr )
1413
+ public function getMethodParameters (int $ stackPtr )
1406
1414
{
1407
1415
if ($ this ->tokens [$ stackPtr ]['code ' ] !== T_FUNCTION
1408
1416
&& $ this ->tokens [$ stackPtr ]['code ' ] !== T_CLOSURE
@@ -1713,7 +1721,7 @@ public function getMethodParameters($stackPtr)
1713
1721
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a
1714
1722
* T_FUNCTION, T_CLOSURE, or T_FN token.
1715
1723
*/
1716
- public function getMethodProperties ($ stackPtr )
1724
+ public function getMethodProperties (int $ stackPtr )
1717
1725
{
1718
1726
if ($ this ->tokens [$ stackPtr ]['code ' ] !== T_FUNCTION
1719
1727
&& $ this ->tokens [$ stackPtr ]['code ' ] !== T_CLOSURE
@@ -1901,7 +1909,7 @@ public function getMethodProperties($stackPtr)
1901
1909
* T_VARIABLE token, or if the position is not
1902
1910
* a class member variable.
1903
1911
*/
1904
- public function getMemberProperties ($ stackPtr )
1912
+ public function getMemberProperties (int $ stackPtr )
1905
1913
{
1906
1914
if ($ this ->tokens [$ stackPtr ]['code ' ] !== T_VARIABLE ) {
1907
1915
throw new RuntimeException ('$stackPtr must be of type T_VARIABLE ' );
@@ -2086,7 +2094,7 @@ public function getMemberProperties($stackPtr)
2086
2094
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a
2087
2095
* T_CLASS token.
2088
2096
*/
2089
- public function getClassProperties ($ stackPtr )
2097
+ public function getClassProperties (int $ stackPtr )
2090
2098
{
2091
2099
if ($ this ->tokens [$ stackPtr ]['code ' ] !== T_CLASS ) {
2092
2100
throw new RuntimeException ('$stackPtr must be of type T_CLASS ' );
@@ -2143,7 +2151,7 @@ public function getClassProperties($stackPtr)
2143
2151
*
2144
2152
* @return boolean
2145
2153
*/
2146
- public function isReference ($ stackPtr )
2154
+ public function isReference (int $ stackPtr )
2147
2155
{
2148
2156
if ($ this ->tokens [$ stackPtr ]['code ' ] !== T_BITWISE_AND ) {
2149
2157
return false ;
@@ -2256,7 +2264,7 @@ public function isReference($stackPtr)
2256
2264
* @return string The token contents.
2257
2265
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position does not exist.
2258
2266
*/
2259
- public function getTokensAsString ($ start , $ length , $ origContent =false )
2267
+ public function getTokensAsString ($ start , $ length , bool $ origContent =false )
2260
2268
{
2261
2269
if (is_int ($ start ) === false || isset ($ this ->tokens [$ start ]) === false ) {
2262
2270
throw new RuntimeException ('The $start position for getTokensAsString() must exist in the token stack ' );
@@ -2315,11 +2323,11 @@ public function getTokensAsString($start, $length, $origContent=false)
2315
2323
*/
2316
2324
public function findPrevious (
2317
2325
$ types ,
2318
- $ start ,
2319
- $ end =null ,
2320
- $ exclude =false ,
2321
- $ value =null ,
2322
- $ local =false
2326
+ int $ start ,
2327
+ ? int $ end =null ,
2328
+ bool $ exclude =false ,
2329
+ ? string $ value =null ,
2330
+ bool $ local =false
2323
2331
) {
2324
2332
$ types = (array ) $ types ;
2325
2333
@@ -2396,11 +2404,11 @@ public function findPrevious(
2396
2404
*/
2397
2405
public function findNext (
2398
2406
$ types ,
2399
- $ start ,
2400
- $ end =null ,
2401
- $ exclude =false ,
2402
- $ value =null ,
2403
- $ local =false
2407
+ int $ start ,
2408
+ ? int $ end =null ,
2409
+ bool $ exclude =false ,
2410
+ ? string $ value =null ,
2411
+ bool $ local =false
2404
2412
) {
2405
2413
$ types = (array ) $ types ;
2406
2414
@@ -2443,7 +2451,7 @@ public function findNext(
2443
2451
*
2444
2452
* @return int
2445
2453
*/
2446
- public function findStartOfStatement ($ start , $ ignore =null )
2454
+ public function findStartOfStatement (int $ start , $ ignore =null )
2447
2455
{
2448
2456
$ startTokens = Tokens::BLOCK_OPENERS ;
2449
2457
$ startTokens [T_OPEN_SHORT_ARRAY ] = true ;
@@ -2634,7 +2642,7 @@ public function findStartOfStatement($start, $ignore=null)
2634
2642
*
2635
2643
* @return int
2636
2644
*/
2637
- public function findEndOfStatement ($ start , $ ignore =null )
2645
+ public function findEndOfStatement (int $ start , $ ignore =null )
2638
2646
{
2639
2647
$ endTokens = [
2640
2648
T_COLON => true ,
@@ -2761,7 +2769,7 @@ public function findEndOfStatement($start, $ignore=null)
2761
2769
* FALSE when no matching token could be found between the start of
2762
2770
* the line and the start token.
2763
2771
*/
2764
- public function findFirstOnLine ($ types , $ start , $ exclude =false , $ value =null )
2772
+ public function findFirstOnLine ($ types , int $ start , bool $ exclude =false , ? string $ value =null )
2765
2773
{
2766
2774
if (is_array ($ types ) === false ) {
2767
2775
$ types = [$ types ];
@@ -2811,7 +2819,7 @@ public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2811
2819
*
2812
2820
* @return boolean
2813
2821
*/
2814
- public function hasCondition ($ stackPtr , $ types )
2822
+ public function hasCondition (int $ stackPtr , $ types )
2815
2823
{
2816
2824
// Check for the existence of the token.
2817
2825
if (isset ($ this ->tokens [$ stackPtr ]) === false ) {
@@ -2852,7 +2860,7 @@ public function hasCondition($stackPtr, $types)
2852
2860
*
2853
2861
* @return int|false
2854
2862
*/
2855
- public function getCondition ($ stackPtr , $ type , $ first =true )
2863
+ public function getCondition (int $ stackPtr , $ type , bool $ first =true )
2856
2864
{
2857
2865
// Check for the existence of the token.
2858
2866
if (isset ($ this ->tokens [$ stackPtr ]) === false ) {
@@ -2890,7 +2898,7 @@ public function getCondition($stackPtr, $type, $first=true)
2890
2898
*
2891
2899
* @return string|false
2892
2900
*/
2893
- public function findExtendedClassName ($ stackPtr )
2901
+ public function findExtendedClassName (int $ stackPtr )
2894
2902
{
2895
2903
// Check for the existence of the token.
2896
2904
if (isset ($ this ->tokens [$ stackPtr ]) === false ) {
@@ -2939,7 +2947,7 @@ public function findExtendedClassName($stackPtr)
2939
2947
*
2940
2948
* @return array|false
2941
2949
*/
2942
- public function findImplementedInterfaceNames ($ stackPtr )
2950
+ public function findImplementedInterfaceNames (int $ stackPtr )
2943
2951
{
2944
2952
// Check for the existence of the token.
2945
2953
if (isset ($ this ->tokens [$ stackPtr ]) === false ) {
0 commit comments