Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
PHPCompatibility/Sniffs/Syntax/RemovedNewReferenceSniff.php 4 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -31,47 +31,47 @@
 block discarded – undo
31 31
 class RemovedNewReferenceSniff extends Sniff
32 32
 {
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(\T_NEW);
42
-    }
34
+	/**
35
+	 * Returns an array of tokens this test wants to listen for.
36
+	 *
37
+	 * @return array
38
+	 */
39
+	public function register()
40
+	{
41
+		return array(\T_NEW);
42
+	}
43 43
 
44
-    /**
45
-     * Processes this test, when one of its tokens is encountered.
46
-     *
47
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
-     * @param int                   $stackPtr  The position of the current token in the
49
-     *                                         stack passed in $tokens.
50
-     *
51
-     * @return void
52
-     */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
55
-        if ($this->supportsAbove('5.3') === false) {
56
-            return;
57
-        }
44
+	/**
45
+	 * Processes this test, when one of its tokens is encountered.
46
+	 *
47
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
+	 * @param int                   $stackPtr  The position of the current token in the
49
+	 *                                         stack passed in $tokens.
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function process(File $phpcsFile, $stackPtr)
54
+	{
55
+		if ($this->supportsAbove('5.3') === false) {
56
+			return;
57
+		}
58 58
 
59
-        $tokens       = $phpcsFile->getTokens();
60
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
-        if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') {
62
-            return;
63
-        }
59
+		$tokens       = $phpcsFile->getTokens();
60
+		$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
+		if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') {
62
+			return;
63
+		}
64 64
 
65
-        $error     = 'Assigning the return value of new by reference is deprecated in PHP 5.3';
66
-        $isError   = false;
67
-        $errorCode = 'Deprecated';
65
+		$error     = 'Assigning the return value of new by reference is deprecated in PHP 5.3';
66
+		$isError   = false;
67
+		$errorCode = 'Deprecated';
68 68
 
69
-        if ($this->supportsAbove('7.0') === true) {
70
-            $error    .= ' and has been removed in PHP 7.0';
71
-            $isError   = true;
72
-            $errorCode = 'Removed';
73
-        }
69
+		if ($this->supportsAbove('7.0') === true) {
70
+			$error    .= ' and has been removed in PHP 7.0';
71
+			$isError   = true;
72
+			$errorCode = 'Removed';
73
+		}
74 74
 
75
-        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode);
76
-    }
75
+		$this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode);
76
+	}
77 77
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(\T_NEW);
41
+        return array( \T_NEW );
42 42
     }
43 43
 
44 44
     /**
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return void
52 52
      */
53
-    public function process(File $phpcsFile, $stackPtr)
53
+    public function process( File $phpcsFile, $stackPtr )
54 54
     {
55
-        if ($this->supportsAbove('5.3') === false) {
55
+        if ( $this->supportsAbove( '5.3' ) === false ) {
56 56
             return;
57 57
         }
58 58
 
59 59
         $tokens       = $phpcsFile->getTokens();
60
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
-        if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') {
60
+        $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
61
+        if ( $prevNonEmpty === false || $tokens[ $prevNonEmpty ][ 'type' ] !== 'T_BITWISE_AND' ) {
62 62
             return;
63 63
         }
64 64
 
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
         $isError   = false;
67 67
         $errorCode = 'Deprecated';
68 68
 
69
-        if ($this->supportsAbove('7.0') === true) {
69
+        if ( $this->supportsAbove( '7.0' ) === true ) {
70 70
             $error    .= ' and has been removed in PHP 7.0';
71 71
             $isError   = true;
72 72
             $errorCode = 'Removed';
73 73
         }
74 74
 
75
-        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode);
75
+        $this->addMessage( $phpcsFile, $error, $stackPtr, $isError, $errorCode );
76 76
     }
77 77
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,16 +28,14 @@  discard block
 block discarded – undo
28 28
  * @author    Wim Godden <[email protected]>
29 29
  * @copyright 2012 Cu.be Solutions bvba
30 30
  */
31
-class RemovedNewReferenceSniff extends Sniff
32
-{
31
+class RemovedNewReferenceSniff extends Sniff {
33 32
 
34 33
     /**
35 34
      * Returns an array of tokens this test wants to listen for.
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(\T_NEW);
42 40
     }
43 41
 
@@ -50,8 +48,7 @@  discard block
 block discarded – undo
50 48
      *
51 49
      * @return void
52 50
      */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
51
+    public function process(File $phpcsFile, $stackPtr) {
55 52
         if ($this->supportsAbove('5.3') === false) {
56 53
             return;
57 54
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewFunctionCallTrailingCommaSniff.php 4 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -26,90 +26,90 @@
 block discarded – undo
26 26
  */
27 27
 class NewFunctionCallTrailingCommaSniff extends Sniff
28 28
 {
29
-    /**
30
-     * Returns an array of tokens this test wants to listen for.
31
-     *
32
-     * @return array
33
-     */
34
-    public function register()
35
-    {
36
-        return array(
37
-            \T_STRING,
38
-            \T_VARIABLE,
39
-            \T_ISSET,
40
-            \T_UNSET,
41
-        );
42
-    }
29
+	/**
30
+	 * Returns an array of tokens this test wants to listen for.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function register()
35
+	{
36
+		return array(
37
+			\T_STRING,
38
+			\T_VARIABLE,
39
+			\T_ISSET,
40
+			\T_UNSET,
41
+		);
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
-     * @param int                   $stackPtr  The position of the current token in
50
-     *                                         the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        if ($this->supportsBelow('7.2') === false) {
57
-            return;
58
-        }
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
+	 * @param int                   $stackPtr  The position of the current token in
50
+	 *                                         the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		if ($this->supportsBelow('7.2') === false) {
57
+			return;
58
+		}
59 59
 
60
-        $tokens = $phpcsFile->getTokens();
60
+		$tokens = $phpcsFile->getTokens();
61 61
 
62
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
63
-        if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
64
-            || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
65
-        ) {
66
-            return;
67
-        }
62
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
63
+		if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
64
+			|| isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
65
+		) {
66
+			return;
67
+		}
68 68
 
69
-        if ($tokens[$stackPtr]['code'] === \T_STRING) {
70
-            $ignore = array(
71
-                \T_FUNCTION        => true,
72
-                \T_CONST           => true,
73
-                \T_USE             => true,
74
-            );
69
+		if ($tokens[$stackPtr]['code'] === \T_STRING) {
70
+			$ignore = array(
71
+				\T_FUNCTION        => true,
72
+				\T_CONST           => true,
73
+				\T_USE             => true,
74
+			);
75 75
 
76
-            $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
77
-            if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
78
-                // Not a function call.
79
-                return;
80
-            }
81
-        }
76
+			$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
77
+			if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
78
+				// Not a function call.
79
+				return;
80
+			}
81
+		}
82 82
 
83
-        $closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
-        $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);
83
+		$closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
+		$lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);
85 85
 
86
-        if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
87
-            return;
88
-        }
86
+		if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
87
+			return;
88
+		}
89 89
 
90
-        $data = array();
91
-        switch ($tokens[$stackPtr]['code']) {
92
-            case \T_ISSET:
93
-                $data[]    = 'calls to isset()';
94
-                $errorCode = 'FoundInIsset';
95
-                break;
90
+		$data = array();
91
+		switch ($tokens[$stackPtr]['code']) {
92
+			case \T_ISSET:
93
+				$data[]    = 'calls to isset()';
94
+				$errorCode = 'FoundInIsset';
95
+				break;
96 96
 
97
-            case \T_UNSET:
98
-                $data[]    = 'calls to unset()';
99
-                $errorCode = 'FoundInUnset';
100
-                break;
97
+			case \T_UNSET:
98
+				$data[]    = 'calls to unset()';
99
+				$errorCode = 'FoundInUnset';
100
+				break;
101 101
 
102
-            default:
103
-                $data[]    = 'function calls';
104
-                $errorCode = 'FoundInFunctionCall';
105
-                break;
106
-        }
102
+			default:
103
+				$data[]    = 'function calls';
104
+				$errorCode = 'FoundInFunctionCall';
105
+				break;
106
+		}
107 107
 
108
-        $phpcsFile->addError(
109
-            'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier',
110
-            $lastInParenthesis,
111
-            $errorCode,
112
-            $data
113
-        );
114
-    }
108
+		$phpcsFile->addError(
109
+			'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier',
110
+			$lastInParenthesis,
111
+			$errorCode,
112
+			$data
113
+		);
114
+	}
115 115
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -51,56 +51,56 @@
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56
-        if ($this->supportsBelow('7.2') === false) {
56
+        if ( $this->supportsBelow( '7.2' ) === false ) {
57 57
             return;
58 58
         }
59 59
 
60 60
         $tokens = $phpcsFile->getTokens();
61 61
 
62
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
63
-        if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
64
-            || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
62
+        $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
63
+        if ( $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS
64
+            || isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false
65 65
         ) {
66 66
             return;
67 67
         }
68 68
 
69
-        if ($tokens[$stackPtr]['code'] === \T_STRING) {
69
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING ) {
70 70
             $ignore = array(
71 71
                 \T_FUNCTION        => true,
72 72
                 \T_CONST           => true,
73 73
                 \T_USE             => true,
74 74
             );
75 75
 
76
-            $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
77
-            if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
76
+            $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
77
+            if ( isset( $ignore[ $tokens[ $prevNonEmpty ][ 'code' ] ] ) === true ) {
78 78
                 // Not a function call.
79 79
                 return;
80 80
             }
81 81
         }
82 82
 
83
-        $closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
-        $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);
83
+        $closer            = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ];
84
+        $lastInParenthesis = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $closer - 1 ), $nextNonEmpty, true );
85 85
 
86
-        if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
86
+        if ( $tokens[ $lastInParenthesis ][ 'code' ] !== \T_COMMA ) {
87 87
             return;
88 88
         }
89 89
 
90 90
         $data = array();
91
-        switch ($tokens[$stackPtr]['code']) {
91
+        switch ( $tokens[ $stackPtr ][ 'code' ] ) {
92 92
             case \T_ISSET:
93
-                $data[]    = 'calls to isset()';
93
+                $data[ ]    = 'calls to isset()';
94 94
                 $errorCode = 'FoundInIsset';
95 95
                 break;
96 96
 
97 97
             case \T_UNSET:
98
-                $data[]    = 'calls to unset()';
98
+                $data[ ]    = 'calls to unset()';
99 99
                 $errorCode = 'FoundInUnset';
100 100
                 break;
101 101
 
102 102
             default:
103
-                $data[]    = 'function calls';
103
+                $data[ ]    = 'function calls';
104 104
                 $errorCode = 'FoundInFunctionCall';
105 105
                 break;
106 106
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,15 +24,13 @@  discard block
 block discarded – undo
24 24
  * @package  PHPCompatibility
25 25
  * @author   Juliette Reinders Folmer <[email protected]>
26 26
  */
27
-class NewFunctionCallTrailingCommaSniff extends Sniff
28
-{
27
+class NewFunctionCallTrailingCommaSniff extends Sniff {
29 28
     /**
30 29
      * Returns an array of tokens this test wants to listen for.
31 30
      *
32 31
      * @return array
33 32
      */
34
-    public function register()
35
-    {
33
+    public function register() {
36 34
         return array(
37 35
             \T_STRING,
38 36
             \T_VARIABLE,
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         if ($this->supportsBelow('7.2') === false) {
57 54
             return;
58 55
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewFlexibleHeredocNowdocSniff.php 3 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -33,215 +33,215 @@
 block discarded – undo
33 33
 class NewFlexibleHeredocNowdocSniff extends Sniff
34 34
 {
35 35
 
36
-    /**
37
-     * Returns an array of tokens this test wants to listen for.
38
-     *
39
-     * @return array
40
-     */
41
-    public function register()
42
-    {
43
-        $targets = array(
44
-            \T_END_HEREDOC,
45
-            \T_END_NOWDOC,
46
-        );
47
-
48
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) {
49
-            // Start identifier of a PHP 7.3 flexible heredoc/nowdoc.
50
-            $targets[] = \T_STRING;
51
-        }
52
-
53
-        return $targets;
54
-    }
55
-
56
-
57
-    /**
58
-     * Processes this test, when one of its tokens is encountered.
59
-     *
60
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
-     * @param int                   $stackPtr  The position of the current token in the
62
-     *                                         stack passed in $tokens.
63
-     *
64
-     * @return void
65
-     */
66
-    public function process(File $phpcsFile, $stackPtr)
67
-    {
68
-        /*
36
+	/**
37
+	 * Returns an array of tokens this test wants to listen for.
38
+	 *
39
+	 * @return array
40
+	 */
41
+	public function register()
42
+	{
43
+		$targets = array(
44
+			\T_END_HEREDOC,
45
+			\T_END_NOWDOC,
46
+		);
47
+
48
+		if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) {
49
+			// Start identifier of a PHP 7.3 flexible heredoc/nowdoc.
50
+			$targets[] = \T_STRING;
51
+		}
52
+
53
+		return $targets;
54
+	}
55
+
56
+
57
+	/**
58
+	 * Processes this test, when one of its tokens is encountered.
59
+	 *
60
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
+	 * @param int                   $stackPtr  The position of the current token in the
62
+	 *                                         stack passed in $tokens.
63
+	 *
64
+	 * @return void
65
+	 */
66
+	public function process(File $phpcsFile, $stackPtr)
67
+	{
68
+		/*
69 69
          * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
70 70
          * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
71 71
          * See upstream issue #928.
72 72
          */
73
-        if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
74
-            $this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
75
-        }
76
-
77
-        $tokens = $phpcsFile->getTokens();
78
-        if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
79
-            $this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
80
-        }
81
-    }
82
-
83
-
84
-    /**
85
-     * Detect indented and/or non-stand alone closing markers.
86
-     *
87
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
88
-     * @param int                   $stackPtr  The position of the current token in the
89
-     *                                         stack passed in $tokens.
90
-     *
91
-     * @return void
92
-     */
93
-    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
94
-    {
95
-        $tokens            = $phpcsFile->getTokens();
96
-        $indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
97
-        $indentErrorCode   = 'IndentedClosingMarker';
98
-        $trailingError     = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.';
99
-        $trailingErrorCode = 'ClosingMarkerNoNewLine';
100
-
101
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
102
-
103
-            /*
73
+		if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
74
+			$this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
75
+		}
76
+
77
+		$tokens = $phpcsFile->getTokens();
78
+		if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
79
+			$this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
80
+		}
81
+	}
82
+
83
+
84
+	/**
85
+	 * Detect indented and/or non-stand alone closing markers.
86
+	 *
87
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
88
+	 * @param int                   $stackPtr  The position of the current token in the
89
+	 *                                         stack passed in $tokens.
90
+	 *
91
+	 * @return void
92
+	 */
93
+	protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
94
+	{
95
+		$tokens            = $phpcsFile->getTokens();
96
+		$indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
97
+		$indentErrorCode   = 'IndentedClosingMarker';
98
+		$trailingError     = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.';
99
+		$trailingErrorCode = 'ClosingMarkerNoNewLine';
100
+
101
+		if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
102
+
103
+			/*
104 104
              * Check for indented closing marker.
105 105
              */
106
-            if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) {
107
-                $phpcsFile->addError($indentError, $stackPtr, $indentErrorCode);
108
-            }
106
+			if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) {
107
+				$phpcsFile->addError($indentError, $stackPtr, $indentErrorCode);
108
+			}
109 109
 
110
-            /*
110
+			/*
111 111
              * Check for tokens after the closing marker.
112 112
              */
113
-            $nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true);
114
-            if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) {
115
-                $phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode);
116
-            }
117
-        } else {
118
-            // For PHP < 7.3, we're only interested in T_STRING tokens.
119
-            if ($tokens[$stackPtr]['code'] !== \T_STRING) {
120
-                return;
121
-            }
113
+			$nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true);
114
+			if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) {
115
+				$phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode);
116
+			}
117
+		} else {
118
+			// For PHP < 7.3, we're only interested in T_STRING tokens.
119
+			if ($tokens[$stackPtr]['code'] !== \T_STRING) {
120
+				return;
121
+			}
122 122
 
123
-            if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) {
124
-                // Not the start of a PHP 7.3 flexible heredoc/nowdoc.
125
-                return;
126
-            }
123
+			if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) {
124
+				// Not the start of a PHP 7.3 flexible heredoc/nowdoc.
125
+				return;
126
+			}
127 127
 
128
-            $identifier = $matches[2];
128
+			$identifier = $matches[2];
129 129
 
130
-            for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) {
131
-                if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) {
132
-                    continue;
133
-                }
130
+			for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) {
131
+				if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) {
132
+					continue;
133
+				}
134 134
 
135
-                $trimmed = ltrim($tokens[$i]['content']);
135
+				$trimmed = ltrim($tokens[$i]['content']);
136 136
 
137
-                if (strpos($trimmed, $identifier) !== 0) {
138
-                    continue;
139
-                }
137
+				if (strpos($trimmed, $identifier) !== 0) {
138
+					continue;
139
+				}
140 140
 
141
-                // OK, we've found the PHP 7.3 flexible heredoc/nowdoc closing marker.
141
+				// OK, we've found the PHP 7.3 flexible heredoc/nowdoc closing marker.
142 142
 
143
-                /*
143
+				/*
144 144
                  * Check for indented closing marker.
145 145
                  */
146
-                if ($trimmed !== $tokens[$i]['content']) {
147
-                    // Indent found before closing marker.
148
-                    $phpcsFile->addError($indentError, $i, $indentErrorCode);
149
-                }
146
+				if ($trimmed !== $tokens[$i]['content']) {
147
+					// Indent found before closing marker.
148
+					$phpcsFile->addError($indentError, $i, $indentErrorCode);
149
+				}
150 150
 
151
-                /*
151
+				/*
152 152
                  * Check for tokens after the closing marker.
153 153
                  */
154
-                // Remove the identifier.
155
-                $afterMarker = substr($trimmed, \strlen($identifier));
156
-                // Remove a potential semi-colon at the beginning of what's left of the string.
157
-                $afterMarker = ltrim($afterMarker, ';');
158
-                // Remove new line characters at the end of the string.
159
-                $afterMarker = rtrim($afterMarker, "\r\n");
160
-
161
-                if ($afterMarker !== '') {
162
-                    $phpcsFile->addError($trailingError, $i, $trailingErrorCode);
163
-                }
164
-
165
-                break;
166
-            }
167
-        }
168
-    }
169
-
170
-
171
-    /**
172
-     * Detect heredoc/nowdoc identifiers at the start of lines in the heredoc/nowdoc body.
173
-     *
174
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
175
-     * @param int                   $stackPtr  The position of the current token in the
176
-     *                                         stack passed in $tokens.
177
-     *
178
-     * @return void
179
-     */
180
-    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
181
-    {
182
-        $tokens    = $phpcsFile->getTokens();
183
-        $error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184
-        $errorCode = 'ClosingMarkerNoNewLine';
185
-
186
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
187
-            $nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true);
188
-            if ($nextNonWhitespace === false
189
-                || $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON
190
-                || (($tokens[$nextNonWhitespace]['code'] === \T_COMMA
191
-                    || $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT)
192
-                    && $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line'])
193
-            ) {
194
-                // This is most likely a correctly identified closing marker.
195
-                return;
196
-            }
197
-
198
-            // The real closing tag has to be before the next heredoc/nowdoc.
199
-            $nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1));
200
-            if ($nextHereNowDoc === false) {
201
-                $nextHereNowDoc = null;
202
-            }
203
-
204
-            $identifier        = trim($tokens[$stackPtr]['content']);
205
-            $realClosingMarker = $stackPtr;
206
-
207
-            while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) {
208
-
209
-                $prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true);
210
-                if ($prevNonWhitespace === false
211
-                    || $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line']
212
-                ) {
213
-                    // Marker text found, but not at the start of the line.
214
-                    continue;
215
-                }
216
-
217
-                // The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found
218
-                // a possible alternative closing marker.
219
-                $phpcsFile->addError($error, $stackPtr, $errorCode);
220
-
221
-                break;
222
-            }
223
-
224
-        } else {
225
-            if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true
226
-                && $tokens[$stackPtr]['scope_closer'] === $stackPtr
227
-            ) {
228
-                $opener = $tokens[$stackPtr]['scope_opener'];
229
-            } else {
230
-                // PHPCS < 3.0.2 did not add scope_* values for Nowdocs.
231
-                $opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1));
232
-                if ($opener === false) {
233
-                    return;
234
-                }
235
-            }
236
-
237
-            $quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`');
238
-
239
-            // Throw an error for each line in the body which starts with the identifier.
240
-            for ($i = ($opener + 1); $i < $stackPtr; $i++) {
241
-                if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) {
242
-                    $phpcsFile->addError($error, $i, $errorCode);
243
-                }
244
-            }
245
-        }
246
-    }
154
+				// Remove the identifier.
155
+				$afterMarker = substr($trimmed, \strlen($identifier));
156
+				// Remove a potential semi-colon at the beginning of what's left of the string.
157
+				$afterMarker = ltrim($afterMarker, ';');
158
+				// Remove new line characters at the end of the string.
159
+				$afterMarker = rtrim($afterMarker, "\r\n");
160
+
161
+				if ($afterMarker !== '') {
162
+					$phpcsFile->addError($trailingError, $i, $trailingErrorCode);
163
+				}
164
+
165
+				break;
166
+			}
167
+		}
168
+	}
169
+
170
+
171
+	/**
172
+	 * Detect heredoc/nowdoc identifiers at the start of lines in the heredoc/nowdoc body.
173
+	 *
174
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
175
+	 * @param int                   $stackPtr  The position of the current token in the
176
+	 *                                         stack passed in $tokens.
177
+	 *
178
+	 * @return void
179
+	 */
180
+	protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
181
+	{
182
+		$tokens    = $phpcsFile->getTokens();
183
+		$error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184
+		$errorCode = 'ClosingMarkerNoNewLine';
185
+
186
+		if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
187
+			$nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true);
188
+			if ($nextNonWhitespace === false
189
+				|| $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON
190
+				|| (($tokens[$nextNonWhitespace]['code'] === \T_COMMA
191
+					|| $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT)
192
+					&& $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line'])
193
+			) {
194
+				// This is most likely a correctly identified closing marker.
195
+				return;
196
+			}
197
+
198
+			// The real closing tag has to be before the next heredoc/nowdoc.
199
+			$nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1));
200
+			if ($nextHereNowDoc === false) {
201
+				$nextHereNowDoc = null;
202
+			}
203
+
204
+			$identifier        = trim($tokens[$stackPtr]['content']);
205
+			$realClosingMarker = $stackPtr;
206
+
207
+			while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) {
208
+
209
+				$prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true);
210
+				if ($prevNonWhitespace === false
211
+					|| $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line']
212
+				) {
213
+					// Marker text found, but not at the start of the line.
214
+					continue;
215
+				}
216
+
217
+				// The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found
218
+				// a possible alternative closing marker.
219
+				$phpcsFile->addError($error, $stackPtr, $errorCode);
220
+
221
+				break;
222
+			}
223
+
224
+		} else {
225
+			if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true
226
+				&& $tokens[$stackPtr]['scope_closer'] === $stackPtr
227
+			) {
228
+				$opener = $tokens[$stackPtr]['scope_opener'];
229
+			} else {
230
+				// PHPCS < 3.0.2 did not add scope_* values for Nowdocs.
231
+				$opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1));
232
+				if ($opener === false) {
233
+					return;
234
+				}
235
+			}
236
+
237
+			$quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`');
238
+
239
+			// Throw an error for each line in the body which starts with the identifier.
240
+			for ($i = ($opener + 1); $i < $stackPtr; $i++) {
241
+				if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) {
242
+					$phpcsFile->addError($error, $i, $errorCode);
243
+				}
244
+			}
245
+		}
246
+	}
247 247
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
             \T_END_NOWDOC,
46 46
         );
47 47
 
48
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) {
48
+        if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === false ) {
49 49
             // Start identifier of a PHP 7.3 flexible heredoc/nowdoc.
50
-            $targets[] = \T_STRING;
50
+            $targets[ ] = \T_STRING;
51 51
         }
52 52
 
53 53
         return $targets;
@@ -63,20 +63,20 @@  discard block
 block discarded – undo
63 63
      *
64 64
      * @return void
65 65
      */
66
-    public function process(File $phpcsFile, $stackPtr)
66
+    public function process( File $phpcsFile, $stackPtr )
67 67
     {
68 68
         /*
69 69
          * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
70 70
          * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
71 71
          * See upstream issue #928.
72 72
          */
73
-        if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
74
-            $this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
73
+        if ( $this->supportsBelow( '7.2' ) === true && version_compare( PHPCSHelper::getVersion(), '2.6.0', '>=' ) ) {
74
+            $this->detectIndentedNonStandAloneClosingMarker( $phpcsFile, $stackPtr );
75 75
         }
76 76
 
77 77
         $tokens = $phpcsFile->getTokens();
78
-        if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
79
-            $this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
78
+        if ( $this->supportsAbove( '7.3' ) === true && $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) {
79
+            $this->detectClosingMarkerInBody( $phpcsFile, $stackPtr );
80 80
         }
81 81
     }
82 82
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return void
92 92
      */
93
-    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
93
+    protected function detectIndentedNonStandAloneClosingMarker( File $phpcsFile, $stackPtr )
94 94
     {
95 95
         $tokens            = $phpcsFile->getTokens();
96 96
         $indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
@@ -98,43 +98,43 @@  discard block
 block discarded – undo
98 98
         $trailingError     = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.';
99 99
         $trailingErrorCode = 'ClosingMarkerNoNewLine';
100 100
 
101
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
101
+        if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === true ) {
102 102
 
103 103
             /*
104 104
              * Check for indented closing marker.
105 105
              */
106
-            if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) {
107
-                $phpcsFile->addError($indentError, $stackPtr, $indentErrorCode);
106
+            if ( ltrim( $tokens[ $stackPtr ][ 'content' ] ) !== $tokens[ $stackPtr ][ 'content' ] ) {
107
+                $phpcsFile->addError( $indentError, $stackPtr, $indentErrorCode );
108 108
             }
109 109
 
110 110
             /*
111 111
              * Check for tokens after the closing marker.
112 112
              */
113
-            $nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true);
114
-            if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) {
115
-                $phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode);
113
+            $nextNonWhitespace = $phpcsFile->findNext( array( \T_WHITESPACE, \T_SEMICOLON ), ( $stackPtr + 1 ), null, true );
114
+            if ( $tokens[ $stackPtr ][ 'line' ] === $tokens[ $nextNonWhitespace ][ 'line' ] ) {
115
+                $phpcsFile->addError( $trailingError, $stackPtr, $trailingErrorCode );
116 116
             }
117 117
         } else {
118 118
             // For PHP < 7.3, we're only interested in T_STRING tokens.
119
-            if ($tokens[$stackPtr]['code'] !== \T_STRING) {
119
+            if ( $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) {
120 120
                 return;
121 121
             }
122 122
 
123
-            if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) {
123
+            if ( preg_match( '`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[ $stackPtr ][ 'content' ], $matches ) !== 1 ) {
124 124
                 // Not the start of a PHP 7.3 flexible heredoc/nowdoc.
125 125
                 return;
126 126
             }
127 127
 
128
-            $identifier = $matches[2];
128
+            $identifier = $matches[ 2 ];
129 129
 
130
-            for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) {
131
-                if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) {
130
+            for ( $i = ( $stackPtr + 1 ); $i <= $phpcsFile->numTokens; $i++ ) {
131
+                if ( $tokens[ $i ][ 'code' ] !== \T_ENCAPSED_AND_WHITESPACE ) {
132 132
                     continue;
133 133
                 }
134 134
 
135
-                $trimmed = ltrim($tokens[$i]['content']);
135
+                $trimmed = ltrim( $tokens[ $i ][ 'content' ] );
136 136
 
137
-                if (strpos($trimmed, $identifier) !== 0) {
137
+                if ( strpos( $trimmed, $identifier ) !== 0 ) {
138 138
                     continue;
139 139
                 }
140 140
 
@@ -143,23 +143,23 @@  discard block
 block discarded – undo
143 143
                 /*
144 144
                  * Check for indented closing marker.
145 145
                  */
146
-                if ($trimmed !== $tokens[$i]['content']) {
146
+                if ( $trimmed !== $tokens[ $i ][ 'content' ] ) {
147 147
                     // Indent found before closing marker.
148
-                    $phpcsFile->addError($indentError, $i, $indentErrorCode);
148
+                    $phpcsFile->addError( $indentError, $i, $indentErrorCode );
149 149
                 }
150 150
 
151 151
                 /*
152 152
                  * Check for tokens after the closing marker.
153 153
                  */
154 154
                 // Remove the identifier.
155
-                $afterMarker = substr($trimmed, \strlen($identifier));
155
+                $afterMarker = substr( $trimmed, \strlen( $identifier ) );
156 156
                 // Remove a potential semi-colon at the beginning of what's left of the string.
157
-                $afterMarker = ltrim($afterMarker, ';');
157
+                $afterMarker = ltrim( $afterMarker, ';' );
158 158
                 // Remove new line characters at the end of the string.
159
-                $afterMarker = rtrim($afterMarker, "\r\n");
159
+                $afterMarker = rtrim( $afterMarker, "\r\n" );
160 160
 
161
-                if ($afterMarker !== '') {
162
-                    $phpcsFile->addError($trailingError, $i, $trailingErrorCode);
161
+                if ( $afterMarker !== '' ) {
162
+                    $phpcsFile->addError( $trailingError, $i, $trailingErrorCode );
163 163
                 }
164 164
 
165 165
                 break;
@@ -177,38 +177,38 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @return void
179 179
      */
180
-    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
180
+    protected function detectClosingMarkerInBody( File $phpcsFile, $stackPtr )
181 181
     {
182 182
         $tokens    = $phpcsFile->getTokens();
183 183
         $error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184 184
         $errorCode = 'ClosingMarkerNoNewLine';
185 185
 
186
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
187
-            $nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true);
188
-            if ($nextNonWhitespace === false
189
-                || $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON
190
-                || (($tokens[$nextNonWhitespace]['code'] === \T_COMMA
191
-                    || $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT)
192
-                    && $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line'])
186
+        if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === true ) {
187
+            $nextNonWhitespace = $phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true, null, true );
188
+            if ( $nextNonWhitespace === false
189
+                || $tokens[ $nextNonWhitespace ][ 'code' ] === \T_SEMICOLON
190
+                || ( ( $tokens[ $nextNonWhitespace ][ 'code' ] === \T_COMMA
191
+                    || $tokens[ $nextNonWhitespace ][ 'code' ] === \T_STRING_CONCAT )
192
+                    && $tokens[ $nextNonWhitespace ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] )
193 193
             ) {
194 194
                 // This is most likely a correctly identified closing marker.
195 195
                 return;
196 196
             }
197 197
 
198 198
             // The real closing tag has to be before the next heredoc/nowdoc.
199
-            $nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1));
200
-            if ($nextHereNowDoc === false) {
199
+            $nextHereNowDoc = $phpcsFile->findNext( array( \T_START_HEREDOC, \T_START_NOWDOC ), ( $stackPtr + 1 ) );
200
+            if ( $nextHereNowDoc === false ) {
201 201
                 $nextHereNowDoc = null;
202 202
             }
203 203
 
204
-            $identifier        = trim($tokens[$stackPtr]['content']);
204
+            $identifier        = trim( $tokens[ $stackPtr ][ 'content' ] );
205 205
             $realClosingMarker = $stackPtr;
206 206
 
207
-            while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) {
207
+            while ( ( $realClosingMarker = $phpcsFile->findNext( \T_STRING, ( $realClosingMarker + 1 ), $nextHereNowDoc, false, $identifier ) ) !== false ) {
208 208
 
209
-                $prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true);
210
-                if ($prevNonWhitespace === false
211
-                    || $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line']
209
+                $prevNonWhitespace = $phpcsFile->findPrevious( \T_WHITESPACE, ( $realClosingMarker - 1 ), null, true );
210
+                if ( $prevNonWhitespace === false
211
+                    || $tokens[ $prevNonWhitespace ][ 'line' ] === $tokens[ $realClosingMarker ][ 'line' ]
212 212
                 ) {
213 213
                     // Marker text found, but not at the start of the line.
214 214
                     continue;
@@ -216,30 +216,30 @@  discard block
 block discarded – undo
216 216
 
217 217
                 // The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found
218 218
                 // a possible alternative closing marker.
219
-                $phpcsFile->addError($error, $stackPtr, $errorCode);
219
+                $phpcsFile->addError( $error, $stackPtr, $errorCode );
220 220
 
221 221
                 break;
222 222
             }
223 223
 
224 224
         } else {
225
-            if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true
226
-                && $tokens[$stackPtr]['scope_closer'] === $stackPtr
225
+            if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ], $tokens[ $stackPtr ][ 'scope_opener' ] ) === true
226
+                && $tokens[ $stackPtr ][ 'scope_closer' ] === $stackPtr
227 227
             ) {
228
-                $opener = $tokens[$stackPtr]['scope_opener'];
228
+                $opener = $tokens[ $stackPtr ][ 'scope_opener' ];
229 229
             } else {
230 230
                 // PHPCS < 3.0.2 did not add scope_* values for Nowdocs.
231
-                $opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1));
232
-                if ($opener === false) {
231
+                $opener = $phpcsFile->findPrevious( \T_START_NOWDOC, ( $stackPtr - 1 ) );
232
+                if ( $opener === false ) {
233 233
                     return;
234 234
                 }
235 235
             }
236 236
 
237
-            $quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`');
237
+            $quotedIdentifier = preg_quote( $tokens[ $stackPtr ][ 'content' ], '`' );
238 238
 
239 239
             // Throw an error for each line in the body which starts with the identifier.
240
-            for ($i = ($opener + 1); $i < $stackPtr; $i++) {
241
-                if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) {
242
-                    $phpcsFile->addError($error, $i, $errorCode);
240
+            for ( $i = ( $opener + 1 ); $i < $stackPtr; $i++ ) {
241
+                if ( preg_match( '`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[ $i ][ 'content' ] ) === 1 ) {
242
+                    $phpcsFile->addError( $error, $i, $errorCode );
243 243
                 }
244 244
             }
245 245
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,16 +30,14 @@  discard block
 block discarded – undo
30 30
  * @package  PHPCompatibility
31 31
  * @author   Juliette Reinders Folmer <[email protected]>
32 32
  */
33
-class NewFlexibleHeredocNowdocSniff extends Sniff
34
-{
33
+class NewFlexibleHeredocNowdocSniff extends Sniff {
35 34
 
36 35
     /**
37 36
      * Returns an array of tokens this test wants to listen for.
38 37
      *
39 38
      * @return array
40 39
      */
41
-    public function register()
42
-    {
40
+    public function register() {
43 41
         $targets = array(
44 42
             \T_END_HEREDOC,
45 43
             \T_END_NOWDOC,
@@ -63,8 +61,7 @@  discard block
 block discarded – undo
63 61
      *
64 62
      * @return void
65 63
      */
66
-    public function process(File $phpcsFile, $stackPtr)
67
-    {
64
+    public function process(File $phpcsFile, $stackPtr) {
68 65
         /*
69 66
          * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
70 67
          * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
@@ -90,8 +87,7 @@  discard block
 block discarded – undo
90 87
      *
91 88
      * @return void
92 89
      */
93
-    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
94
-    {
90
+    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr) {
95 91
         $tokens            = $phpcsFile->getTokens();
96 92
         $indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
97 93
         $indentErrorCode   = 'IndentedClosingMarker';
@@ -177,8 +173,7 @@  discard block
 block discarded – undo
177 173
      *
178 174
      * @return void
179 175
      */
180
-    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
181
-    {
176
+    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr) {
182 177
         $tokens    = $phpcsFile->getTokens();
183 178
         $error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184 179
         $errorCode = 'ClosingMarkerNoNewLine';
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/ForbiddenCallTimePassByReferenceSniff.php 4 patches
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -33,221 +33,221 @@
 block discarded – undo
33 33
 class ForbiddenCallTimePassByReferenceSniff extends Sniff
34 34
 {
35 35
 
36
-    /**
37
-     * Tokens that represent assignments or equality comparisons.
38
-     *
39
-     * Near duplicate of Tokens::$assignmentTokens + Tokens::$equalityTokens.
40
-     * Copied in for PHPCS cross-version compatibility.
41
-     *
42
-     * @var array
43
-     */
44
-    private $assignOrCompare = array(
45
-        // Equality tokens.
46
-        'T_IS_EQUAL'            => true,
47
-        'T_IS_NOT_EQUAL'        => true,
48
-        'T_IS_IDENTICAL'        => true,
49
-        'T_IS_NOT_IDENTICAL'    => true,
50
-        'T_IS_SMALLER_OR_EQUAL' => true,
51
-        'T_IS_GREATER_OR_EQUAL' => true,
52
-
53
-        // Assignment tokens.
54
-        'T_EQUAL'          => true,
55
-        'T_AND_EQUAL'      => true,
56
-        'T_OR_EQUAL'       => true,
57
-        'T_CONCAT_EQUAL'   => true,
58
-        'T_DIV_EQUAL'      => true,
59
-        'T_MINUS_EQUAL'    => true,
60
-        'T_POW_EQUAL'      => true,
61
-        'T_MOD_EQUAL'      => true,
62
-        'T_MUL_EQUAL'      => true,
63
-        'T_PLUS_EQUAL'     => true,
64
-        'T_XOR_EQUAL'      => true,
65
-        'T_DOUBLE_ARROW'   => true,
66
-        'T_SL_EQUAL'       => true,
67
-        'T_SR_EQUAL'       => true,
68
-        'T_COALESCE_EQUAL' => true,
69
-        'T_ZSR_EQUAL'      => true,
70
-    );
71
-
72
-    /**
73
-     * Returns an array of tokens this test wants to listen for.
74
-     *
75
-     * @return array
76
-     */
77
-    public function register()
78
-    {
79
-        return array(
80
-            \T_STRING,
81
-            \T_VARIABLE,
82
-        );
83
-    }
84
-
85
-    /**
86
-     * Processes this test, when one of its tokens is encountered.
87
-     *
88
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
89
-     * @param int                   $stackPtr  The position of the current token
90
-     *                                         in the stack passed in $tokens.
91
-     *
92
-     * @return void
93
-     */
94
-    public function process(File $phpcsFile, $stackPtr)
95
-    {
96
-        if ($this->supportsAbove('5.3') === false) {
97
-            return;
98
-        }
99
-
100
-        $tokens = $phpcsFile->getTokens();
101
-
102
-        // Skip tokens that are the names of functions or classes
103
-        // within their definitions. For example: function myFunction...
104
-        // "myFunction" is T_STRING but we should skip because it is not a
105
-        // function or method *call*.
106
-        $findTokens   = Tokens::$emptyTokens;
107
-        $findTokens[] = \T_BITWISE_AND;
108
-
109
-        $prevNonEmpty = $phpcsFile->findPrevious(
110
-            $findTokens,
111
-            ($stackPtr - 1),
112
-            null,
113
-            true
114
-        );
115
-
116
-        if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
117
-            return;
118
-        }
119
-
120
-        // If the next non-whitespace token after the function or method call
121
-        // is not an opening parenthesis then it can't really be a *call*.
122
-        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
123
-
124
-        if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS
125
-            || isset($tokens[$openBracket]['parenthesis_closer']) === false
126
-        ) {
127
-            return;
128
-        }
129
-
130
-        // Get the function call parameters.
131
-        $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
132
-        if (\count($parameters) === 0) {
133
-            return;
134
-        }
135
-
136
-        // Which nesting level is the one we are interested in ?
137
-        $nestedParenthesisCount = 1;
138
-        if (isset($tokens[$openBracket]['nested_parenthesis'])) {
139
-            $nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1;
140
-        }
141
-
142
-        foreach ($parameters as $parameter) {
143
-            if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
144
-                // T_BITWISE_AND represents a pass-by-reference.
145
-                $error     = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
146
-                $isError   = false;
147
-                $errorCode = 'Deprecated';
148
-
149
-                if ($this->supportsAbove('5.4')) {
150
-                    $error    .= ' and prohibited since PHP 5.4';
151
-                    $isError   = true;
152
-                    $errorCode = 'NotAllowed';
153
-                }
154
-
155
-                $this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode);
156
-            }
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Determine whether a parameter is passed by reference.
163
-     *
164
-     * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
165
-     * @param array                 $parameter    Information on the current parameter
166
-     *                                            to be examined.
167
-     * @param int                   $nestingLevel Target nesting level.
168
-     *
169
-     * @return bool
170
-     */
171
-    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
172
-    {
173
-        $tokens = $phpcsFile->getTokens();
174
-
175
-        $searchStartToken = $parameter['start'] - 1;
176
-        $searchEndToken   = $parameter['end'] + 1;
177
-        $nextVariable     = $searchStartToken;
178
-        do {
179
-            $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
180
-            if ($nextVariable === false) {
181
-                return false;
182
-            }
183
-
184
-            // Ignore anything within short array definition brackets.
185
-            if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
186
-                && (isset($tokens[$nextVariable]['bracket_opener'])
187
-                    && $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
188
-                && isset($tokens[$nextVariable]['bracket_closer'])
189
-            ) {
190
-                // Skip forward to the end of the short array definition.
191
-                $nextVariable = $tokens[$nextVariable]['bracket_closer'];
192
-                continue;
193
-            }
194
-
195
-            // Skip past closures passed as function parameters.
196
-            if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
197
-                && (isset($tokens[$nextVariable]['scope_condition'])
198
-                    && $tokens[$nextVariable]['scope_condition'] === $nextVariable)
199
-                && isset($tokens[$nextVariable]['scope_closer'])
200
-            ) {
201
-                // Skip forward to the end of the closure declaration.
202
-                $nextVariable = $tokens[$nextVariable]['scope_closer'];
203
-                continue;
204
-            }
205
-
206
-            // Make sure the variable belongs directly to this function call
207
-            // and is not inside a nested function call or array.
208
-            if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
209
-                || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
210
-            ) {
211
-                continue;
212
-            }
213
-
214
-            // Checking this: $value = my_function(...[*]$arg...).
215
-            $tokenBefore = $phpcsFile->findPrevious(
216
-                Tokens::$emptyTokens,
217
-                ($nextVariable - 1),
218
-                $searchStartToken,
219
-                true
220
-            );
221
-
222
-            if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
223
-                // Nothing before the token or no &.
224
-                continue;
225
-            }
226
-
227
-            if ($phpcsFile->isReference($tokenBefore) === false) {
228
-                continue;
229
-            }
230
-
231
-            // Checking this: $value = my_function(...[*]&$arg...).
232
-            $tokenBefore = $phpcsFile->findPrevious(
233
-                Tokens::$emptyTokens,
234
-                ($tokenBefore - 1),
235
-                $searchStartToken,
236
-                true
237
-            );
238
-
239
-            // Prevent false positive on assign by reference and compare with reference
240
-            // within function call parameters.
241
-            if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
242
-                continue;
243
-            }
244
-
245
-            // The found T_BITWISE_AND represents a pass-by-reference.
246
-            return true;
247
-
248
-        } while ($nextVariable < $searchEndToken);
249
-
250
-        // This code should never be reached, but here in case of weird bugs.
251
-        return false;
252
-    }
36
+	/**
37
+	 * Tokens that represent assignments or equality comparisons.
38
+	 *
39
+	 * Near duplicate of Tokens::$assignmentTokens + Tokens::$equalityTokens.
40
+	 * Copied in for PHPCS cross-version compatibility.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	private $assignOrCompare = array(
45
+		// Equality tokens.
46
+		'T_IS_EQUAL'            => true,
47
+		'T_IS_NOT_EQUAL'        => true,
48
+		'T_IS_IDENTICAL'        => true,
49
+		'T_IS_NOT_IDENTICAL'    => true,
50
+		'T_IS_SMALLER_OR_EQUAL' => true,
51
+		'T_IS_GREATER_OR_EQUAL' => true,
52
+
53
+		// Assignment tokens.
54
+		'T_EQUAL'          => true,
55
+		'T_AND_EQUAL'      => true,
56
+		'T_OR_EQUAL'       => true,
57
+		'T_CONCAT_EQUAL'   => true,
58
+		'T_DIV_EQUAL'      => true,
59
+		'T_MINUS_EQUAL'    => true,
60
+		'T_POW_EQUAL'      => true,
61
+		'T_MOD_EQUAL'      => true,
62
+		'T_MUL_EQUAL'      => true,
63
+		'T_PLUS_EQUAL'     => true,
64
+		'T_XOR_EQUAL'      => true,
65
+		'T_DOUBLE_ARROW'   => true,
66
+		'T_SL_EQUAL'       => true,
67
+		'T_SR_EQUAL'       => true,
68
+		'T_COALESCE_EQUAL' => true,
69
+		'T_ZSR_EQUAL'      => true,
70
+	);
71
+
72
+	/**
73
+	 * Returns an array of tokens this test wants to listen for.
74
+	 *
75
+	 * @return array
76
+	 */
77
+	public function register()
78
+	{
79
+		return array(
80
+			\T_STRING,
81
+			\T_VARIABLE,
82
+		);
83
+	}
84
+
85
+	/**
86
+	 * Processes this test, when one of its tokens is encountered.
87
+	 *
88
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
89
+	 * @param int                   $stackPtr  The position of the current token
90
+	 *                                         in the stack passed in $tokens.
91
+	 *
92
+	 * @return void
93
+	 */
94
+	public function process(File $phpcsFile, $stackPtr)
95
+	{
96
+		if ($this->supportsAbove('5.3') === false) {
97
+			return;
98
+		}
99
+
100
+		$tokens = $phpcsFile->getTokens();
101
+
102
+		// Skip tokens that are the names of functions or classes
103
+		// within their definitions. For example: function myFunction...
104
+		// "myFunction" is T_STRING but we should skip because it is not a
105
+		// function or method *call*.
106
+		$findTokens   = Tokens::$emptyTokens;
107
+		$findTokens[] = \T_BITWISE_AND;
108
+
109
+		$prevNonEmpty = $phpcsFile->findPrevious(
110
+			$findTokens,
111
+			($stackPtr - 1),
112
+			null,
113
+			true
114
+		);
115
+
116
+		if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
117
+			return;
118
+		}
119
+
120
+		// If the next non-whitespace token after the function or method call
121
+		// is not an opening parenthesis then it can't really be a *call*.
122
+		$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
123
+
124
+		if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS
125
+			|| isset($tokens[$openBracket]['parenthesis_closer']) === false
126
+		) {
127
+			return;
128
+		}
129
+
130
+		// Get the function call parameters.
131
+		$parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
132
+		if (\count($parameters) === 0) {
133
+			return;
134
+		}
135
+
136
+		// Which nesting level is the one we are interested in ?
137
+		$nestedParenthesisCount = 1;
138
+		if (isset($tokens[$openBracket]['nested_parenthesis'])) {
139
+			$nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1;
140
+		}
141
+
142
+		foreach ($parameters as $parameter) {
143
+			if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
144
+				// T_BITWISE_AND represents a pass-by-reference.
145
+				$error     = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
146
+				$isError   = false;
147
+				$errorCode = 'Deprecated';
148
+
149
+				if ($this->supportsAbove('5.4')) {
150
+					$error    .= ' and prohibited since PHP 5.4';
151
+					$isError   = true;
152
+					$errorCode = 'NotAllowed';
153
+				}
154
+
155
+				$this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode);
156
+			}
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Determine whether a parameter is passed by reference.
163
+	 *
164
+	 * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
165
+	 * @param array                 $parameter    Information on the current parameter
166
+	 *                                            to be examined.
167
+	 * @param int                   $nestingLevel Target nesting level.
168
+	 *
169
+	 * @return bool
170
+	 */
171
+	protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
172
+	{
173
+		$tokens = $phpcsFile->getTokens();
174
+
175
+		$searchStartToken = $parameter['start'] - 1;
176
+		$searchEndToken   = $parameter['end'] + 1;
177
+		$nextVariable     = $searchStartToken;
178
+		do {
179
+			$nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
180
+			if ($nextVariable === false) {
181
+				return false;
182
+			}
183
+
184
+			// Ignore anything within short array definition brackets.
185
+			if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
186
+				&& (isset($tokens[$nextVariable]['bracket_opener'])
187
+					&& $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
188
+				&& isset($tokens[$nextVariable]['bracket_closer'])
189
+			) {
190
+				// Skip forward to the end of the short array definition.
191
+				$nextVariable = $tokens[$nextVariable]['bracket_closer'];
192
+				continue;
193
+			}
194
+
195
+			// Skip past closures passed as function parameters.
196
+			if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
197
+				&& (isset($tokens[$nextVariable]['scope_condition'])
198
+					&& $tokens[$nextVariable]['scope_condition'] === $nextVariable)
199
+				&& isset($tokens[$nextVariable]['scope_closer'])
200
+			) {
201
+				// Skip forward to the end of the closure declaration.
202
+				$nextVariable = $tokens[$nextVariable]['scope_closer'];
203
+				continue;
204
+			}
205
+
206
+			// Make sure the variable belongs directly to this function call
207
+			// and is not inside a nested function call or array.
208
+			if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
209
+				|| (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
210
+			) {
211
+				continue;
212
+			}
213
+
214
+			// Checking this: $value = my_function(...[*]$arg...).
215
+			$tokenBefore = $phpcsFile->findPrevious(
216
+				Tokens::$emptyTokens,
217
+				($nextVariable - 1),
218
+				$searchStartToken,
219
+				true
220
+			);
221
+
222
+			if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
223
+				// Nothing before the token or no &.
224
+				continue;
225
+			}
226
+
227
+			if ($phpcsFile->isReference($tokenBefore) === false) {
228
+				continue;
229
+			}
230
+
231
+			// Checking this: $value = my_function(...[*]&$arg...).
232
+			$tokenBefore = $phpcsFile->findPrevious(
233
+				Tokens::$emptyTokens,
234
+				($tokenBefore - 1),
235
+				$searchStartToken,
236
+				true
237
+			);
238
+
239
+			// Prevent false positive on assign by reference and compare with reference
240
+			// within function call parameters.
241
+			if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
242
+				continue;
243
+			}
244
+
245
+			// The found T_BITWISE_AND represents a pass-by-reference.
246
+			return true;
247
+
248
+		} while ($nextVariable < $searchEndToken);
249
+
250
+		// This code should never be reached, but here in case of weird bugs.
251
+		return false;
252
+	}
253 253
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      *
92 92
      * @return void
93 93
      */
94
-    public function process(File $phpcsFile, $stackPtr)
94
+    public function process( File $phpcsFile, $stackPtr )
95 95
     {
96
-        if ($this->supportsAbove('5.3') === false) {
96
+        if ( $this->supportsAbove( '5.3' ) === false ) {
97 97
             return;
98 98
         }
99 99
 
@@ -104,55 +104,55 @@  discard block
 block discarded – undo
104 104
         // "myFunction" is T_STRING but we should skip because it is not a
105 105
         // function or method *call*.
106 106
         $findTokens   = Tokens::$emptyTokens;
107
-        $findTokens[] = \T_BITWISE_AND;
107
+        $findTokens[ ] = \T_BITWISE_AND;
108 108
 
109 109
         $prevNonEmpty = $phpcsFile->findPrevious(
110 110
             $findTokens,
111
-            ($stackPtr - 1),
111
+            ( $stackPtr - 1 ),
112 112
             null,
113 113
             true
114 114
         );
115 115
 
116
-        if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
116
+        if ( $prevNonEmpty !== false && \in_array( $tokens[ $prevNonEmpty ][ 'type' ], array( 'T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT' ), true ) ) {
117 117
             return;
118 118
         }
119 119
 
120 120
         // If the next non-whitespace token after the function or method call
121 121
         // is not an opening parenthesis then it can't really be a *call*.
122
-        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
122
+        $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
123 123
 
124
-        if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS
125
-            || isset($tokens[$openBracket]['parenthesis_closer']) === false
124
+        if ( $openBracket === false || $tokens[ $openBracket ][ 'code' ] !== \T_OPEN_PARENTHESIS
125
+            || isset( $tokens[ $openBracket ][ 'parenthesis_closer' ] ) === false
126 126
         ) {
127 127
             return;
128 128
         }
129 129
 
130 130
         // Get the function call parameters.
131
-        $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
132
-        if (\count($parameters) === 0) {
131
+        $parameters = $this->getFunctionCallParameters( $phpcsFile, $stackPtr );
132
+        if ( \count( $parameters ) === 0 ) {
133 133
             return;
134 134
         }
135 135
 
136 136
         // Which nesting level is the one we are interested in ?
137 137
         $nestedParenthesisCount = 1;
138
-        if (isset($tokens[$openBracket]['nested_parenthesis'])) {
139
-            $nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1;
138
+        if ( isset( $tokens[ $openBracket ][ 'nested_parenthesis' ] ) ) {
139
+            $nestedParenthesisCount = \count( $tokens[ $openBracket ][ 'nested_parenthesis' ] ) + 1;
140 140
         }
141 141
 
142
-        foreach ($parameters as $parameter) {
143
-            if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
142
+        foreach ( $parameters as $parameter ) {
143
+            if ( $this->isCallTimePassByReferenceParam( $phpcsFile, $parameter, $nestedParenthesisCount ) === true ) {
144 144
                 // T_BITWISE_AND represents a pass-by-reference.
145 145
                 $error     = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
146 146
                 $isError   = false;
147 147
                 $errorCode = 'Deprecated';
148 148
 
149
-                if ($this->supportsAbove('5.4')) {
149
+                if ( $this->supportsAbove( '5.4' ) ) {
150 150
                     $error    .= ' and prohibited since PHP 5.4';
151 151
                     $isError   = true;
152 152
                     $errorCode = 'NotAllowed';
153 153
                 }
154 154
 
155
-                $this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode);
155
+                $this->addMessage( $phpcsFile, $error, $parameter[ 'start' ], $isError, $errorCode );
156 156
             }
157 157
         }
158 158
     }
@@ -168,45 +168,45 @@  discard block
 block discarded – undo
168 168
      *
169 169
      * @return bool
170 170
      */
171
-    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
171
+    protected function isCallTimePassByReferenceParam( File $phpcsFile, $parameter, $nestingLevel )
172 172
     {
173 173
         $tokens = $phpcsFile->getTokens();
174 174
 
175
-        $searchStartToken = $parameter['start'] - 1;
176
-        $searchEndToken   = $parameter['end'] + 1;
175
+        $searchStartToken = $parameter[ 'start' ] - 1;
176
+        $searchEndToken   = $parameter[ 'end' ] + 1;
177 177
         $nextVariable     = $searchStartToken;
178 178
         do {
179
-            $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
180
-            if ($nextVariable === false) {
179
+            $nextVariable = $phpcsFile->findNext( array( \T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $nextVariable + 1 ), $searchEndToken );
180
+            if ( $nextVariable === false ) {
181 181
                 return false;
182 182
             }
183 183
 
184 184
             // Ignore anything within short array definition brackets.
185
-            if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
186
-                && (isset($tokens[$nextVariable]['bracket_opener'])
187
-                    && $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
188
-                && isset($tokens[$nextVariable]['bracket_closer'])
185
+            if ( $tokens[ $nextVariable ][ 'type' ] === 'T_OPEN_SHORT_ARRAY'
186
+                && ( isset( $tokens[ $nextVariable ][ 'bracket_opener' ] )
187
+                    && $tokens[ $nextVariable ][ 'bracket_opener' ] === $nextVariable )
188
+                && isset( $tokens[ $nextVariable ][ 'bracket_closer' ] )
189 189
             ) {
190 190
                 // Skip forward to the end of the short array definition.
191
-                $nextVariable = $tokens[$nextVariable]['bracket_closer'];
191
+                $nextVariable = $tokens[ $nextVariable ][ 'bracket_closer' ];
192 192
                 continue;
193 193
             }
194 194
 
195 195
             // Skip past closures passed as function parameters.
196
-            if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
197
-                && (isset($tokens[$nextVariable]['scope_condition'])
198
-                    && $tokens[$nextVariable]['scope_condition'] === $nextVariable)
199
-                && isset($tokens[$nextVariable]['scope_closer'])
196
+            if ( $tokens[ $nextVariable ][ 'type' ] === 'T_CLOSURE'
197
+                && ( isset( $tokens[ $nextVariable ][ 'scope_condition' ] )
198
+                    && $tokens[ $nextVariable ][ 'scope_condition' ] === $nextVariable )
199
+                && isset( $tokens[ $nextVariable ][ 'scope_closer' ] )
200 200
             ) {
201 201
                 // Skip forward to the end of the closure declaration.
202
-                $nextVariable = $tokens[$nextVariable]['scope_closer'];
202
+                $nextVariable = $tokens[ $nextVariable ][ 'scope_closer' ];
203 203
                 continue;
204 204
             }
205 205
 
206 206
             // Make sure the variable belongs directly to this function call
207 207
             // and is not inside a nested function call or array.
208
-            if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
209
-                || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
208
+            if ( isset( $tokens[ $nextVariable ][ 'nested_parenthesis' ] ) === false
209
+                || ( \count( $tokens[ $nextVariable ][ 'nested_parenthesis' ] ) !== $nestingLevel )
210 210
             ) {
211 211
                 continue;
212 212
             }
@@ -214,38 +214,38 @@  discard block
 block discarded – undo
214 214
             // Checking this: $value = my_function(...[*]$arg...).
215 215
             $tokenBefore = $phpcsFile->findPrevious(
216 216
                 Tokens::$emptyTokens,
217
-                ($nextVariable - 1),
217
+                ( $nextVariable - 1 ),
218 218
                 $searchStartToken,
219 219
                 true
220 220
             );
221 221
 
222
-            if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
222
+            if ( $tokenBefore === false || $tokens[ $tokenBefore ][ 'code' ] !== \T_BITWISE_AND ) {
223 223
                 // Nothing before the token or no &.
224 224
                 continue;
225 225
             }
226 226
 
227
-            if ($phpcsFile->isReference($tokenBefore) === false) {
227
+            if ( $phpcsFile->isReference( $tokenBefore ) === false ) {
228 228
                 continue;
229 229
             }
230 230
 
231 231
             // Checking this: $value = my_function(...[*]&$arg...).
232 232
             $tokenBefore = $phpcsFile->findPrevious(
233 233
                 Tokens::$emptyTokens,
234
-                ($tokenBefore - 1),
234
+                ( $tokenBefore - 1 ),
235 235
                 $searchStartToken,
236 236
                 true
237 237
             );
238 238
 
239 239
             // Prevent false positive on assign by reference and compare with reference
240 240
             // within function call parameters.
241
-            if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
241
+            if ( isset( $this->assignOrCompare[ $tokens[ $tokenBefore ][ 'type' ] ] ) ) {
242 242
                 continue;
243 243
             }
244 244
 
245 245
             // The found T_BITWISE_AND represents a pass-by-reference.
246 246
             return true;
247 247
 
248
-        } while ($nextVariable < $searchEndToken);
248
+        } while ( $nextVariable < $searchEndToken );
249 249
 
250 250
         // This code should never be reached, but here in case of weird bugs.
251 251
         return false;
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
  * @author    Florian Grandel <[email protected]>
31 31
  * @copyright 2009 Florian Grandel
32 32
  */
33
-class ForbiddenCallTimePassByReferenceSniff extends Sniff
34
-{
33
+class ForbiddenCallTimePassByReferenceSniff extends Sniff {
35 34
 
36 35
     /**
37 36
      * Tokens that represent assignments or equality comparisons.
@@ -74,8 +73,7 @@  discard block
 block discarded – undo
74 73
      *
75 74
      * @return array
76 75
      */
77
-    public function register()
78
-    {
76
+    public function register() {
79 77
         return array(
80 78
             \T_STRING,
81 79
             \T_VARIABLE,
@@ -91,8 +89,7 @@  discard block
 block discarded – undo
91 89
      *
92 90
      * @return void
93 91
      */
94
-    public function process(File $phpcsFile, $stackPtr)
95
-    {
92
+    public function process(File $phpcsFile, $stackPtr) {
96 93
         if ($this->supportsAbove('5.3') === false) {
97 94
             return;
98 95
         }
@@ -168,8 +165,7 @@  discard block
 block discarded – undo
168 165
      *
169 166
      * @return bool
170 167
      */
171
-    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
172
-    {
168
+    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel) {
173 169
         $tokens = $phpcsFile->getTokens();
174 170
 
175 171
         $searchStartToken = $parameter['start'] - 1;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewClassMemberAccessSniff.php 4 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -32,82 +32,82 @@
 block discarded – undo
32 32
 class NewClassMemberAccessSniff extends Sniff
33 33
 {
34 34
 
35
-    /**
36
-     * Returns an array of tokens this test wants to listen for.
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array(
43
-            \T_NEW,
44
-            \T_CLONE,
45
-        );
46
-    }
35
+	/**
36
+	 * Returns an array of tokens this test wants to listen for.
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function register()
41
+	{
42
+		return array(
43
+			\T_NEW,
44
+			\T_CLONE,
45
+		);
46
+	}
47 47
 
48
-    /**
49
-     * Processes this test, when one of its tokens is encountered.
50
-     *
51
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
52
-     * @param int                   $stackPtr  The position of the current token in the
53
-     *                                         stack passed in $tokens.
54
-     *
55
-     * @return void
56
-     */
57
-    public function process(File $phpcsFile, $stackPtr)
58
-    {
59
-        $tokens = $phpcsFile->getTokens();
48
+	/**
49
+	 * Processes this test, when one of its tokens is encountered.
50
+	 *
51
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
52
+	 * @param int                   $stackPtr  The position of the current token in the
53
+	 *                                         stack passed in $tokens.
54
+	 *
55
+	 * @return void
56
+	 */
57
+	public function process(File $phpcsFile, $stackPtr)
58
+	{
59
+		$tokens = $phpcsFile->getTokens();
60 60
 
61
-        if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
62
-            return;
63
-        } elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) {
64
-            return;
65
-        }
61
+		if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
62
+			return;
63
+		} elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) {
64
+			return;
65
+		}
66 66
 
67
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) {
68
-            // The `new className/clone $a` has to be in parentheses, without is not supported.
69
-            return;
70
-        }
67
+		if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) {
68
+			// The `new className/clone $a` has to be in parentheses, without is not supported.
69
+			return;
70
+		}
71 71
 
72
-        $parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']);
73
-        $parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']);
72
+		$parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']);
73
+		$parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']);
74 74
 
75
-        if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) {
76
-            // If there is an owner, these parentheses are for a different purpose.
77
-            return;
78
-        }
75
+		if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) {
76
+			// If there is an owner, these parentheses are for a different purpose.
77
+			return;
78
+		}
79 79
 
80
-        $prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true);
81
-        if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) {
82
-            // This is most likely a function call with the new/cloned object as a parameter.
83
-            return;
84
-        }
80
+		$prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true);
81
+		if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) {
82
+			// This is most likely a function call with the new/cloned object as a parameter.
83
+			return;
84
+		}
85 85
 
86
-        $nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true);
87
-        if ($nextAfterParenthesis === false) {
88
-            // Live coding.
89
-            return;
90
-        }
86
+		$nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true);
87
+		if ($nextAfterParenthesis === false) {
88
+			// Live coding.
89
+			return;
90
+		}
91 91
 
92
-        if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR
93
-            && $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET
94
-        ) {
95
-            return;
96
-        }
92
+		if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR
93
+			&& $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET
94
+		) {
95
+			return;
96
+		}
97 97
 
98
-        $data      = array('instantiation', '5.3');
99
-        $errorCode = 'OnNewFound';
98
+		$data      = array('instantiation', '5.3');
99
+		$errorCode = 'OnNewFound';
100 100
 
101
-        if ($tokens[$stackPtr]['code'] === \T_CLONE) {
102
-            $data      = array('cloning', '5.6');
103
-            $errorCode = 'OnCloneFound';
104
-        }
101
+		if ($tokens[$stackPtr]['code'] === \T_CLONE) {
102
+			$data      = array('cloning', '5.6');
103
+			$errorCode = 'OnCloneFound';
104
+		}
105 105
 
106
-        $phpcsFile->addError(
107
-            'Class member access on object %s was not supported in PHP %s or earlier',
108
-            $parenthesisCloser,
109
-            $errorCode,
110
-            $data
111
-        );
112
-    }
106
+		$phpcsFile->addError(
107
+			'Class member access on object %s was not supported in PHP %s or earlier',
108
+			$parenthesisCloser,
109
+			$errorCode,
110
+			$data
111
+		);
112
+	}
113 113
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -54,52 +54,52 @@
 block discarded – undo
54 54
      *
55 55
      * @return void
56 56
      */
57
-    public function process(File $phpcsFile, $stackPtr)
57
+    public function process( File $phpcsFile, $stackPtr )
58 58
     {
59 59
         $tokens = $phpcsFile->getTokens();
60 60
 
61
-        if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
61
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_NEW && $this->supportsBelow( '5.3' ) !== true ) {
62 62
             return;
63
-        } elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) {
63
+        } elseif ( $tokens[ $stackPtr ][ 'code' ] === \T_CLONE && $this->supportsBelow( '5.6' ) !== true ) {
64 64
             return;
65 65
         }
66 66
 
67
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) {
67
+        if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false ) {
68 68
             // The `new className/clone $a` has to be in parentheses, without is not supported.
69 69
             return;
70 70
         }
71 71
 
72
-        $parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']);
73
-        $parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']);
72
+        $parenthesisCloser = end( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
73
+        $parenthesisOpener = key( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
74 74
 
75
-        if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) {
75
+        if ( isset( $tokens[ $parenthesisOpener ][ 'parenthesis_owner' ] ) === true ) {
76 76
             // If there is an owner, these parentheses are for a different purpose.
77 77
             return;
78 78
         }
79 79
 
80
-        $prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true);
81
-        if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) {
80
+        $prevBeforeParenthesis = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $parenthesisOpener - 1 ), null, true );
81
+        if ( $prevBeforeParenthesis !== false && $tokens[ $prevBeforeParenthesis ][ 'code' ] === \T_STRING ) {
82 82
             // This is most likely a function call with the new/cloned object as a parameter.
83 83
             return;
84 84
         }
85 85
 
86
-        $nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true);
87
-        if ($nextAfterParenthesis === false) {
86
+        $nextAfterParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, ( $parenthesisCloser + 1 ), null, true );
87
+        if ( $nextAfterParenthesis === false ) {
88 88
             // Live coding.
89 89
             return;
90 90
         }
91 91
 
92
-        if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR
93
-            && $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET
92
+        if ( $tokens[ $nextAfterParenthesis ][ 'code' ] !== \T_OBJECT_OPERATOR
93
+            && $tokens[ $nextAfterParenthesis ][ 'code' ] !== \T_OPEN_SQUARE_BRACKET
94 94
         ) {
95 95
             return;
96 96
         }
97 97
 
98
-        $data      = array('instantiation', '5.3');
98
+        $data      = array( 'instantiation', '5.3' );
99 99
         $errorCode = 'OnNewFound';
100 100
 
101
-        if ($tokens[$stackPtr]['code'] === \T_CLONE) {
102
-            $data      = array('cloning', '5.6');
101
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_CLONE ) {
102
+            $data      = array( 'cloning', '5.6' );
103 103
             $errorCode = 'OnCloneFound';
104 104
         }
105 105
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,16 +29,14 @@  discard block
 block discarded – undo
29 29
  * @package  PHPCompatibility
30 30
  * @author   Juliette Reinders Folmer <[email protected]>
31 31
  */
32
-class NewClassMemberAccessSniff extends Sniff
33
-{
32
+class NewClassMemberAccessSniff extends Sniff {
34 33
 
35 34
     /**
36 35
      * Returns an array of tokens this test wants to listen for.
37 36
      *
38 37
      * @return array
39 38
      */
40
-    public function register()
41
-    {
39
+    public function register() {
42 40
         return array(
43 41
             \T_NEW,
44 42
             \T_CLONE,
@@ -54,8 +52,7 @@  discard block
 block discarded – undo
54 52
      *
55 53
      * @return void
56 54
      */
57
-    public function process(File $phpcsFile, $stackPtr)
58
-    {
55
+    public function process(File $phpcsFile, $stackPtr) {
59 56
         $tokens = $phpcsFile->getTokens();
60 57
 
61 58
         if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewFunctionArrayDereferencingSniff.php 4 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -26,70 +26,70 @@
 block discarded – undo
26 26
  */
27 27
 class NewFunctionArrayDereferencingSniff extends Sniff
28 28
 {
29
-    /**
30
-     * Returns an array of tokens this test wants to listen for.
31
-     *
32
-     * @return array
33
-     */
34
-    public function register()
35
-    {
36
-        return array(\T_STRING);
37
-    }
29
+	/**
30
+	 * Returns an array of tokens this test wants to listen for.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function register()
35
+	{
36
+		return array(\T_STRING);
37
+	}
38 38
 
39
-    /**
40
-     * Processes this test, when one of its tokens is encountered.
41
-     *
42
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
43
-     * @param int                   $stackPtr  The position of the current token in
44
-     *                                         the stack passed in $tokens.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        if ($this->supportsBelow('5.3') === false) {
51
-            return;
52
-        }
39
+	/**
40
+	 * Processes this test, when one of its tokens is encountered.
41
+	 *
42
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
43
+	 * @param int                   $stackPtr  The position of the current token in
44
+	 *                                         the stack passed in $tokens.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		if ($this->supportsBelow('5.3') === false) {
51
+			return;
52
+		}
53 53
 
54
-        $tokens = $phpcsFile->getTokens();
54
+		$tokens = $phpcsFile->getTokens();
55 55
 
56
-        // Next non-empty token should be the open parenthesis.
57
-        $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
58
-        if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS) {
59
-            return;
60
-        }
56
+		// Next non-empty token should be the open parenthesis.
57
+		$openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
58
+		if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS) {
59
+			return;
60
+		}
61 61
 
62
-        // Don't throw errors during live coding.
63
-        if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
64
-            return;
65
-        }
62
+		// Don't throw errors during live coding.
63
+		if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
64
+			return;
65
+		}
66 66
 
67
-        // Is this T_STRING really a function or method call ?
68
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
69
-        if ($prevToken !== false && \in_array($tokens[$prevToken]['code'], array(\T_DOUBLE_COLON, \T_OBJECT_OPERATOR), true) === false) {
70
-            $ignore = array(
71
-                \T_FUNCTION  => true,
72
-                \T_CONST     => true,
73
-                \T_USE       => true,
74
-                \T_NEW       => true,
75
-                \T_CLASS     => true,
76
-                \T_INTERFACE => true,
77
-            );
67
+		// Is this T_STRING really a function or method call ?
68
+		$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
69
+		if ($prevToken !== false && \in_array($tokens[$prevToken]['code'], array(\T_DOUBLE_COLON, \T_OBJECT_OPERATOR), true) === false) {
70
+			$ignore = array(
71
+				\T_FUNCTION  => true,
72
+				\T_CONST     => true,
73
+				\T_USE       => true,
74
+				\T_NEW       => true,
75
+				\T_CLASS     => true,
76
+				\T_INTERFACE => true,
77
+			);
78 78
 
79
-            if (isset($ignore[$tokens[$prevToken]['code']]) === true) {
80
-                // Not a call to a PHP function or method.
81
-                return;
82
-            }
83
-        }
79
+			if (isset($ignore[$tokens[$prevToken]['code']]) === true) {
80
+				// Not a call to a PHP function or method.
81
+				return;
82
+			}
83
+		}
84 84
 
85
-        $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
86
-        $nextNonEmpty     = $phpcsFile->findNext(Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true);
87
-        if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') {
88
-            $phpcsFile->addError(
89
-                'Function array dereferencing is not present in PHP version 5.3 or earlier',
90
-                $nextNonEmpty,
91
-                'Found'
92
-            );
93
-        }
94
-    }
85
+		$closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
86
+		$nextNonEmpty     = $phpcsFile->findNext(Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true);
87
+		if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') {
88
+			$phpcsFile->addError(
89
+				'Function array dereferencing is not present in PHP version 5.3 or earlier',
90
+				$nextNonEmpty,
91
+				'Found'
92
+			);
93
+		}
94
+	}
95 95
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function register()
35 35
     {
36
-        return array(\T_STRING);
36
+        return array( \T_STRING );
37 37
     }
38 38
 
39 39
     /**
@@ -45,28 +45,28 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return void
47 47
      */
48
-    public function process(File $phpcsFile, $stackPtr)
48
+    public function process( File $phpcsFile, $stackPtr )
49 49
     {
50
-        if ($this->supportsBelow('5.3') === false) {
50
+        if ( $this->supportsBelow( '5.3' ) === false ) {
51 51
             return;
52 52
         }
53 53
 
54 54
         $tokens = $phpcsFile->getTokens();
55 55
 
56 56
         // Next non-empty token should be the open parenthesis.
57
-        $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
58
-        if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS) {
57
+        $openParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true );
58
+        if ( $openParenthesis === false || $tokens[ $openParenthesis ][ 'code' ] !== \T_OPEN_PARENTHESIS ) {
59 59
             return;
60 60
         }
61 61
 
62 62
         // Don't throw errors during live coding.
63
-        if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
63
+        if ( isset( $tokens[ $openParenthesis ][ 'parenthesis_closer' ] ) === false ) {
64 64
             return;
65 65
         }
66 66
 
67 67
         // Is this T_STRING really a function or method call ?
68
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
69
-        if ($prevToken !== false && \in_array($tokens[$prevToken]['code'], array(\T_DOUBLE_COLON, \T_OBJECT_OPERATOR), true) === false) {
68
+        $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
69
+        if ( $prevToken !== false && \in_array( $tokens[ $prevToken ][ 'code' ], array( \T_DOUBLE_COLON, \T_OBJECT_OPERATOR ), true ) === false ) {
70 70
             $ignore = array(
71 71
                 \T_FUNCTION  => true,
72 72
                 \T_CONST     => true,
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
                 \T_INTERFACE => true,
77 77
             );
78 78
 
79
-            if (isset($ignore[$tokens[$prevToken]['code']]) === true) {
79
+            if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) {
80 80
                 // Not a call to a PHP function or method.
81 81
                 return;
82 82
             }
83 83
         }
84 84
 
85
-        $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
86
-        $nextNonEmpty     = $phpcsFile->findNext(Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true);
87
-        if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') {
85
+        $closeParenthesis = $tokens[ $openParenthesis ][ 'parenthesis_closer' ];
86
+        $nextNonEmpty     = $phpcsFile->findNext( Tokens::$emptyTokens, ( $closeParenthesis + 1 ), null, true, null, true );
87
+        if ( $nextNonEmpty !== false && $tokens[ $nextNonEmpty ][ 'type' ] === 'T_OPEN_SQUARE_BRACKET' ) {
88 88
             $phpcsFile->addError(
89 89
                 'Function array dereferencing is not present in PHP version 5.3 or earlier',
90 90
                 $nextNonEmpty,
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,15 +24,13 @@  discard block
 block discarded – undo
24 24
  * @package  PHPCompatibility
25 25
  * @author   Wim Godden <[email protected]>
26 26
  */
27
-class NewFunctionArrayDereferencingSniff extends Sniff
28
-{
27
+class NewFunctionArrayDereferencingSniff extends Sniff {
29 28
     /**
30 29
      * Returns an array of tokens this test wants to listen for.
31 30
      *
32 31
      * @return array
33 32
      */
34
-    public function register()
35
-    {
33
+    public function register() {
36 34
         return array(\T_STRING);
37 35
     }
38 36
 
@@ -45,8 +43,7 @@  discard block
 block discarded – undo
45 43
      *
46 44
      * @return void
47 45
      */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
46
+    public function process(File $phpcsFile, $stackPtr) {
50 47
         if ($this->supportsBelow('5.3') === false) {
51 48
             return;
52 49
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewArrayStringDereferencingSniff.php 3 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -28,81 +28,81 @@
 block discarded – undo
28 28
  */
29 29
 class NewArrayStringDereferencingSniff extends Sniff
30 30
 {
31
-    /**
32
-     * Returns an array of tokens this test wants to listen for.
33
-     *
34
-     * @return array
35
-     */
36
-    public function register()
37
-    {
38
-        return array(
39
-            \T_ARRAY,
40
-            \T_OPEN_SHORT_ARRAY,
41
-            \T_CONSTANT_ENCAPSED_STRING,
42
-        );
43
-    }
31
+	/**
32
+	 * Returns an array of tokens this test wants to listen for.
33
+	 *
34
+	 * @return array
35
+	 */
36
+	public function register()
37
+	{
38
+		return array(
39
+			\T_ARRAY,
40
+			\T_OPEN_SHORT_ARRAY,
41
+			\T_CONSTANT_ENCAPSED_STRING,
42
+		);
43
+	}
44 44
 
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
-     * @param int                   $stackPtr  The position of the current token in
50
-     *                                         the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        if ($this->supportsBelow('5.4') === false) {
57
-            return;
58
-        }
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
+	 * @param int                   $stackPtr  The position of the current token in
50
+	 *                                         the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		if ($this->supportsBelow('5.4') === false) {
57
+			return;
58
+		}
59 59
 
60
-        $tokens = $phpcsFile->getTokens();
60
+		$tokens = $phpcsFile->getTokens();
61 61
 
62
-        switch ($tokens[$stackPtr]['code']) {
63
-            case \T_CONSTANT_ENCAPSED_STRING:
64
-                $type = 'string literals';
65
-                $end  = $stackPtr;
66
-                break;
62
+		switch ($tokens[$stackPtr]['code']) {
63
+			case \T_CONSTANT_ENCAPSED_STRING:
64
+				$type = 'string literals';
65
+				$end  = $stackPtr;
66
+				break;
67 67
 
68
-            case \T_ARRAY:
69
-                if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) {
70
-                    // Live coding.
71
-                    return;
72
-                } else {
73
-                    $type = 'arrays';
74
-                    $end  = $tokens[$stackPtr]['parenthesis_closer'];
75
-                }
76
-                break;
68
+			case \T_ARRAY:
69
+				if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) {
70
+					// Live coding.
71
+					return;
72
+				} else {
73
+					$type = 'arrays';
74
+					$end  = $tokens[$stackPtr]['parenthesis_closer'];
75
+				}
76
+				break;
77 77
 
78
-            case \T_OPEN_SHORT_ARRAY:
79
-                if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
80
-                    // Live coding.
81
-                    return;
82
-                } else {
83
-                    $type = 'arrays';
84
-                    $end  = $tokens[$stackPtr]['bracket_closer'];
85
-                }
86
-                break;
87
-        }
78
+			case \T_OPEN_SHORT_ARRAY:
79
+				if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
80
+					// Live coding.
81
+					return;
82
+				} else {
83
+					$type = 'arrays';
84
+					$end  = $tokens[$stackPtr]['bracket_closer'];
85
+				}
86
+				break;
87
+		}
88 88
 
89
-        if (isset($type, $end) === false) {
90
-            // Shouldn't happen, but for some reason did.
91
-            return;
92
-        }
89
+		if (isset($type, $end) === false) {
90
+			// Shouldn't happen, but for some reason did.
91
+			return;
92
+		}
93 93
 
94
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true, null, true);
94
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true, null, true);
95 95
 
96
-        if ($nextNonEmpty !== false
97
-            && ($tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET'
98
-                || $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SHORT_ARRAY') // Work around bug #1381 in PHPCS 2.8.1 and lower.
99
-        ) {
100
-            $phpcsFile->addError(
101
-                'Direct array dereferencing of %s is not present in PHP version 5.4 or earlier',
102
-                $nextNonEmpty,
103
-                'Found',
104
-                array($type)
105
-            );
106
-        }
107
-    }
96
+		if ($nextNonEmpty !== false
97
+			&& ($tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET'
98
+				|| $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SHORT_ARRAY') // Work around bug #1381 in PHPCS 2.8.1 and lower.
99
+		) {
100
+			$phpcsFile->addError(
101
+				'Direct array dereferencing of %s is not present in PHP version 5.4 or earlier',
102
+				$nextNonEmpty,
103
+				'Found',
104
+				array($type)
105
+			);
106
+		}
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -51,57 +51,57 @@
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56
-        if ($this->supportsBelow('5.4') === false) {
56
+        if ( $this->supportsBelow( '5.4' ) === false ) {
57 57
             return;
58 58
         }
59 59
 
60 60
         $tokens = $phpcsFile->getTokens();
61 61
 
62
-        switch ($tokens[$stackPtr]['code']) {
62
+        switch ( $tokens[ $stackPtr ][ 'code' ] ) {
63 63
             case \T_CONSTANT_ENCAPSED_STRING:
64 64
                 $type = 'string literals';
65 65
                 $end  = $stackPtr;
66 66
                 break;
67 67
 
68 68
             case \T_ARRAY:
69
-                if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) {
69
+                if ( isset( $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) {
70 70
                     // Live coding.
71 71
                     return;
72 72
                 } else {
73 73
                     $type = 'arrays';
74
-                    $end  = $tokens[$stackPtr]['parenthesis_closer'];
74
+                    $end  = $tokens[ $stackPtr ][ 'parenthesis_closer' ];
75 75
                 }
76 76
                 break;
77 77
 
78 78
             case \T_OPEN_SHORT_ARRAY:
79
-                if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
79
+                if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) === false ) {
80 80
                     // Live coding.
81 81
                     return;
82 82
                 } else {
83 83
                     $type = 'arrays';
84
-                    $end  = $tokens[$stackPtr]['bracket_closer'];
84
+                    $end  = $tokens[ $stackPtr ][ 'bracket_closer' ];
85 85
                 }
86 86
                 break;
87 87
         }
88 88
 
89
-        if (isset($type, $end) === false) {
89
+        if ( isset( $type, $end ) === false ) {
90 90
             // Shouldn't happen, but for some reason did.
91 91
             return;
92 92
         }
93 93
 
94
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true, null, true);
94
+        $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $end + 1 ), null, true, null, true );
95 95
 
96
-        if ($nextNonEmpty !== false
97
-            && ($tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET'
98
-                || $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SHORT_ARRAY') // Work around bug #1381 in PHPCS 2.8.1 and lower.
96
+        if ( $nextNonEmpty !== false
97
+            && ( $tokens[ $nextNonEmpty ][ 'type' ] === 'T_OPEN_SQUARE_BRACKET'
98
+                || $tokens[ $nextNonEmpty ][ 'type' ] === 'T_OPEN_SHORT_ARRAY' ) // Work around bug #1381 in PHPCS 2.8.1 and lower.
99 99
         ) {
100 100
             $phpcsFile->addError(
101 101
                 'Direct array dereferencing of %s is not present in PHP version 5.4 or earlier',
102 102
                 $nextNonEmpty,
103 103
                 'Found',
104
-                array($type)
104
+                array( $type )
105 105
             );
106 106
         }
107 107
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,15 +26,13 @@  discard block
 block discarded – undo
26 26
  * @package  PHPCompatibility
27 27
  * @author   Juliette Reinders Folmer <[email protected]>
28 28
  */
29
-class NewArrayStringDereferencingSniff extends Sniff
30
-{
29
+class NewArrayStringDereferencingSniff extends Sniff {
31 30
     /**
32 31
      * Returns an array of tokens this test wants to listen for.
33 32
      *
34 33
      * @return array
35 34
      */
36
-    public function register()
37
-    {
35
+    public function register() {
38 36
         return array(
39 37
             \T_ARRAY,
40 38
             \T_OPEN_SHORT_ARRAY,
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         if ($this->supportsBelow('5.4') === false) {
57 54
             return;
58 55
         }
Please login to merge, or discard this patch.
php-compatibility/PHPCompatibility/Sniffs/Syntax/NewArrayUnpackingSniff.php 3 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -26,112 +26,112 @@
 block discarded – undo
26 26
 class NewArrayUnpackingSniff extends Sniff
27 27
 {
28 28
 
29
-    /**
30
-     * Returns an array of tokens this test wants to listen for.
31
-     *
32
-     * @return array
33
-     */
34
-    public function register()
35
-    {
36
-        return array(
37
-            \T_ARRAY,
38
-            \T_OPEN_SHORT_ARRAY,
39
-        );
40
-    }
41
-
42
-    /**
43
-     * Processes this test, when one of its tokens is encountered.
44
-     *
45
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
46
-     * @param int                   $stackPtr  The position of the current token in the
47
-     *                                         stack passed in $tokens.
48
-     *
49
-     * @return void
50
-     */
51
-    public function process(File $phpcsFile, $stackPtr)
52
-    {
53
-        if ($this->supportsBelow('7.3') === false) {
54
-            return;
55
-        }
56
-
57
-        $tokens = $phpcsFile->getTokens();
58
-
59
-        /*
29
+	/**
30
+	 * Returns an array of tokens this test wants to listen for.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function register()
35
+	{
36
+		return array(
37
+			\T_ARRAY,
38
+			\T_OPEN_SHORT_ARRAY,
39
+		);
40
+	}
41
+
42
+	/**
43
+	 * Processes this test, when one of its tokens is encountered.
44
+	 *
45
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
46
+	 * @param int                   $stackPtr  The position of the current token in the
47
+	 *                                         stack passed in $tokens.
48
+	 *
49
+	 * @return void
50
+	 */
51
+	public function process(File $phpcsFile, $stackPtr)
52
+	{
53
+		if ($this->supportsBelow('7.3') === false) {
54
+			return;
55
+		}
56
+
57
+		$tokens = $phpcsFile->getTokens();
58
+
59
+		/*
60 60
          * Determine the array opener & closer.
61 61
          */
62
-        $closer = $phpcsFile->numTokens;
63
-        if ($tokens[$stackPtr]['code'] === \T_ARRAY) {
64
-            if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
65
-                return;
66
-            }
67
-
68
-            $opener = $tokens[$stackPtr]['parenthesis_opener'];
69
-
70
-            if (isset($tokens[$opener]['parenthesis_closer'])) {
71
-                $closer = $tokens[$opener]['parenthesis_closer'];
72
-            }
73
-        } else {
74
-            // Short array syntax.
75
-            $opener = $stackPtr;
76
-
77
-            if (isset($tokens[$stackPtr]['bracket_closer'])) {
78
-                $closer = $tokens[$stackPtr]['bracket_closer'];
79
-            }
80
-        }
81
-
82
-        $nestingLevel = 0;
83
-        if (isset($tokens[($opener + 1)]['nested_parenthesis'])) {
84
-            $nestingLevel = count($tokens[($opener + 1)]['nested_parenthesis']);
85
-        }
86
-
87
-        for ($i = $opener; $i < $closer;) {
88
-            $i = $phpcsFile->findNext(array(\T_ELLIPSIS, \T_OPEN_SHORT_ARRAY, \T_ARRAY), ($i + 1), $closer);
89
-            if ($i === false) {
90
-                return;
91
-            }
92
-
93
-            if ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY) {
94
-                if (isset($tokens[$i]['bracket_closer']) === false) {
95
-                    // Live coding, unfinished nested array, handle this when the array opener
96
-                    // of the nested array is passed.
97
-                    return;
98
-                }
99
-
100
-                // Skip over nested short arrays. These will be handled when the array opener
101
-                // of the nested array is passed.
102
-                $i = $tokens[$i]['bracket_closer'];
103
-                continue;
104
-            }
105
-
106
-            if ($tokens[$i]['code'] === \T_ARRAY) {
107
-                if (isset($tokens[$i]['parenthesis_closer']) === false) {
108
-                    // Live coding, unfinished nested array, handle this when the array opener
109
-                    // of the nested array is passed.
110
-                    return;
111
-                }
112
-
113
-                // Skip over nested long arrays. These will be handled when the array opener
114
-                // of the nested array is passed.
115
-                $i = $tokens[$i]['parenthesis_closer'];
116
-                continue;
117
-            }
118
-
119
-            // Ensure this is not function call variable unpacking.
120
-            if (isset($tokens[$i]['nested_parenthesis'])
121
-                && count($tokens[$i]['nested_parenthesis']) > $nestingLevel
122
-            ) {
123
-                continue;
124
-            }
125
-
126
-            // Ok, found one.
127
-            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
128
-            $snippet      = trim($phpcsFile->getTokensAsString($i, (($nextNonEmpty - $i) + 1)));
129
-            $phpcsFile->addError(
130
-                'Array unpacking within array declarations using the spread operator is not supported in PHP 7.3 or earlier. Found: %s',
131
-                $i,
132
-                'Found',
133
-                array($snippet)
134
-            );
135
-        }
136
-    }
62
+		$closer = $phpcsFile->numTokens;
63
+		if ($tokens[$stackPtr]['code'] === \T_ARRAY) {
64
+			if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
65
+				return;
66
+			}
67
+
68
+			$opener = $tokens[$stackPtr]['parenthesis_opener'];
69
+
70
+			if (isset($tokens[$opener]['parenthesis_closer'])) {
71
+				$closer = $tokens[$opener]['parenthesis_closer'];
72
+			}
73
+		} else {
74
+			// Short array syntax.
75
+			$opener = $stackPtr;
76
+
77
+			if (isset($tokens[$stackPtr]['bracket_closer'])) {
78
+				$closer = $tokens[$stackPtr]['bracket_closer'];
79
+			}
80
+		}
81
+
82
+		$nestingLevel = 0;
83
+		if (isset($tokens[($opener + 1)]['nested_parenthesis'])) {
84
+			$nestingLevel = count($tokens[($opener + 1)]['nested_parenthesis']);
85
+		}
86
+
87
+		for ($i = $opener; $i < $closer;) {
88
+			$i = $phpcsFile->findNext(array(\T_ELLIPSIS, \T_OPEN_SHORT_ARRAY, \T_ARRAY), ($i + 1), $closer);
89
+			if ($i === false) {
90
+				return;
91
+			}
92
+
93
+			if ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY) {
94
+				if (isset($tokens[$i]['bracket_closer']) === false) {
95
+					// Live coding, unfinished nested array, handle this when the array opener
96
+					// of the nested array is passed.
97
+					return;
98
+				}
99
+
100
+				// Skip over nested short arrays. These will be handled when the array opener
101
+				// of the nested array is passed.
102
+				$i = $tokens[$i]['bracket_closer'];
103
+				continue;
104
+			}
105
+
106
+			if ($tokens[$i]['code'] === \T_ARRAY) {
107
+				if (isset($tokens[$i]['parenthesis_closer']) === false) {
108
+					// Live coding, unfinished nested array, handle this when the array opener
109
+					// of the nested array is passed.
110
+					return;
111
+				}
112
+
113
+				// Skip over nested long arrays. These will be handled when the array opener
114
+				// of the nested array is passed.
115
+				$i = $tokens[$i]['parenthesis_closer'];
116
+				continue;
117
+			}
118
+
119
+			// Ensure this is not function call variable unpacking.
120
+			if (isset($tokens[$i]['nested_parenthesis'])
121
+				&& count($tokens[$i]['nested_parenthesis']) > $nestingLevel
122
+			) {
123
+				continue;
124
+			}
125
+
126
+			// Ok, found one.
127
+			$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
128
+			$snippet      = trim($phpcsFile->getTokensAsString($i, (($nextNonEmpty - $i) + 1)));
129
+			$phpcsFile->addError(
130
+				'Array unpacking within array declarations using the spread operator is not supported in PHP 7.3 or earlier. Found: %s',
131
+				$i,
132
+				'Found',
133
+				array($snippet)
134
+			);
135
+		}
136
+	}
137 137
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @return void
50 50
      */
51
-    public function process(File $phpcsFile, $stackPtr)
51
+    public function process( File $phpcsFile, $stackPtr )
52 52
     {
53
-        if ($this->supportsBelow('7.3') === false) {
53
+        if ( $this->supportsBelow( '7.3' ) === false ) {
54 54
             return;
55 55
         }
56 56
 
@@ -60,38 +60,38 @@  discard block
 block discarded – undo
60 60
          * Determine the array opener & closer.
61 61
          */
62 62
         $closer = $phpcsFile->numTokens;
63
-        if ($tokens[$stackPtr]['code'] === \T_ARRAY) {
64
-            if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
63
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_ARRAY ) {
64
+            if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ] ) === false ) {
65 65
                 return;
66 66
             }
67 67
 
68
-            $opener = $tokens[$stackPtr]['parenthesis_opener'];
68
+            $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
69 69
 
70
-            if (isset($tokens[$opener]['parenthesis_closer'])) {
71
-                $closer = $tokens[$opener]['parenthesis_closer'];
70
+            if ( isset( $tokens[ $opener ][ 'parenthesis_closer' ] ) ) {
71
+                $closer = $tokens[ $opener ][ 'parenthesis_closer' ];
72 72
             }
73 73
         } else {
74 74
             // Short array syntax.
75 75
             $opener = $stackPtr;
76 76
 
77
-            if (isset($tokens[$stackPtr]['bracket_closer'])) {
78
-                $closer = $tokens[$stackPtr]['bracket_closer'];
77
+            if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) ) {
78
+                $closer = $tokens[ $stackPtr ][ 'bracket_closer' ];
79 79
             }
80 80
         }
81 81
 
82 82
         $nestingLevel = 0;
83
-        if (isset($tokens[($opener + 1)]['nested_parenthesis'])) {
84
-            $nestingLevel = count($tokens[($opener + 1)]['nested_parenthesis']);
83
+        if ( isset( $tokens[ ( $opener + 1 ) ][ 'nested_parenthesis' ] ) ) {
84
+            $nestingLevel = count( $tokens[ ( $opener + 1 ) ][ 'nested_parenthesis' ] );
85 85
         }
86 86
 
87
-        for ($i = $opener; $i < $closer;) {
88
-            $i = $phpcsFile->findNext(array(\T_ELLIPSIS, \T_OPEN_SHORT_ARRAY, \T_ARRAY), ($i + 1), $closer);
89
-            if ($i === false) {
87
+        for ( $i = $opener; $i < $closer; ) {
88
+            $i = $phpcsFile->findNext( array( \T_ELLIPSIS, \T_OPEN_SHORT_ARRAY, \T_ARRAY ), ( $i + 1 ), $closer );
89
+            if ( $i === false ) {
90 90
                 return;
91 91
             }
92 92
 
93
-            if ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY) {
94
-                if (isset($tokens[$i]['bracket_closer']) === false) {
93
+            if ( $tokens[ $i ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) {
94
+                if ( isset( $tokens[ $i ][ 'bracket_closer' ] ) === false ) {
95 95
                     // Live coding, unfinished nested array, handle this when the array opener
96 96
                     // of the nested array is passed.
97 97
                     return;
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
 
100 100
                 // Skip over nested short arrays. These will be handled when the array opener
101 101
                 // of the nested array is passed.
102
-                $i = $tokens[$i]['bracket_closer'];
102
+                $i = $tokens[ $i ][ 'bracket_closer' ];
103 103
                 continue;
104 104
             }
105 105
 
106
-            if ($tokens[$i]['code'] === \T_ARRAY) {
107
-                if (isset($tokens[$i]['parenthesis_closer']) === false) {
106
+            if ( $tokens[ $i ][ 'code' ] === \T_ARRAY ) {
107
+                if ( isset( $tokens[ $i ][ 'parenthesis_closer' ] ) === false ) {
108 108
                     // Live coding, unfinished nested array, handle this when the array opener
109 109
                     // of the nested array is passed.
110 110
                     return;
@@ -112,25 +112,25 @@  discard block
 block discarded – undo
112 112
 
113 113
                 // Skip over nested long arrays. These will be handled when the array opener
114 114
                 // of the nested array is passed.
115
-                $i = $tokens[$i]['parenthesis_closer'];
115
+                $i = $tokens[ $i ][ 'parenthesis_closer' ];
116 116
                 continue;
117 117
             }
118 118
 
119 119
             // Ensure this is not function call variable unpacking.
120
-            if (isset($tokens[$i]['nested_parenthesis'])
121
-                && count($tokens[$i]['nested_parenthesis']) > $nestingLevel
120
+            if ( isset( $tokens[ $i ][ 'nested_parenthesis' ] )
121
+                && count( $tokens[ $i ][ 'nested_parenthesis' ] ) > $nestingLevel
122 122
             ) {
123 123
                 continue;
124 124
             }
125 125
 
126 126
             // Ok, found one.
127
-            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
128
-            $snippet      = trim($phpcsFile->getTokensAsString($i, (($nextNonEmpty - $i) + 1)));
127
+            $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true );
128
+            $snippet      = trim( $phpcsFile->getTokensAsString( $i, ( ( $nextNonEmpty - $i ) + 1 ) ) );
129 129
             $phpcsFile->addError(
130 130
                 'Array unpacking within array declarations using the spread operator is not supported in PHP 7.3 or earlier. Found: %s',
131 131
                 $i,
132 132
                 'Found',
133
-                array($snippet)
133
+                array( $snippet )
134 134
             );
135 135
         }
136 136
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,16 +23,14 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @since 9.2.0
25 25
  */
26
-class NewArrayUnpackingSniff extends Sniff
27
-{
26
+class NewArrayUnpackingSniff extends Sniff {
28 27
 
29 28
     /**
30 29
      * Returns an array of tokens this test wants to listen for.
31 30
      *
32 31
      * @return array
33 32
      */
34
-    public function register()
35
-    {
33
+    public function register() {
36 34
         return array(
37 35
             \T_ARRAY,
38 36
             \T_OPEN_SHORT_ARRAY,
@@ -48,8 +46,7 @@  discard block
 block discarded – undo
48 46
      *
49 47
      * @return void
50 48
      */
51
-    public function process(File $phpcsFile, $stackPtr)
52
-    {
49
+    public function process(File $phpcsFile, $stackPtr) {
53 50
         if ($this->supportsBelow('7.3') === false) {
54 51
             return;
55 52
         }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Operators/NewShortTernarySniff.php 4 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -31,39 +31,39 @@
 block discarded – undo
31 31
 class NewShortTernarySniff extends Sniff
32 32
 {
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(\T_INLINE_THEN);
42
-    }
34
+	/**
35
+	 * Returns an array of tokens this test wants to listen for.
36
+	 *
37
+	 * @return array
38
+	 */
39
+	public function register()
40
+	{
41
+		return array(\T_INLINE_THEN);
42
+	}
43 43
 
44
-    /**
45
-     * Processes this test, when one of its tokens is encountered.
46
-     *
47
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
-     * @param int                   $stackPtr  The position of the current token in the
49
-     *                                         stack passed in $tokens.
50
-     *
51
-     * @return void
52
-     */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
55
-        if ($this->supportsBelow('5.2') === false) {
56
-            return;
57
-        }
44
+	/**
45
+	 * Processes this test, when one of its tokens is encountered.
46
+	 *
47
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
+	 * @param int                   $stackPtr  The position of the current token in the
49
+	 *                                         stack passed in $tokens.
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function process(File $phpcsFile, $stackPtr)
54
+	{
55
+		if ($this->supportsBelow('5.2') === false) {
56
+			return;
57
+		}
58 58
 
59
-        if ($this->isShortTernary($phpcsFile, $stackPtr) === false) {
60
-            return;
61
-        }
59
+		if ($this->isShortTernary($phpcsFile, $stackPtr) === false) {
60
+			return;
61
+		}
62 62
 
63
-        $phpcsFile->addError(
64
-            'Middle may not be omitted from ternary operators in PHP < 5.3',
65
-            $stackPtr,
66
-            'MiddleMissing'
67
-        );
68
-    }
63
+		$phpcsFile->addError(
64
+			'Middle may not be omitted from ternary operators in PHP < 5.3',
65
+			$stackPtr,
66
+			'MiddleMissing'
67
+		);
68
+	}
69 69
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(\T_INLINE_THEN);
41
+        return array( \T_INLINE_THEN );
42 42
     }
43 43
 
44 44
     /**
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return void
52 52
      */
53
-    public function process(File $phpcsFile, $stackPtr)
53
+    public function process( File $phpcsFile, $stackPtr )
54 54
     {
55
-        if ($this->supportsBelow('5.2') === false) {
55
+        if ( $this->supportsBelow( '5.2' ) === false ) {
56 56
             return;
57 57
         }
58 58
 
59
-        if ($this->isShortTernary($phpcsFile, $stackPtr) === false) {
59
+        if ( $this->isShortTernary( $phpcsFile, $stackPtr ) === false ) {
60 60
             return;
61 61
         }
62 62
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,16 +28,14 @@  discard block
 block discarded – undo
28 28
  * @author    Ben Selby <[email protected]>
29 29
  * @copyright 2012 Ben Selby
30 30
  */
31
-class NewShortTernarySniff extends Sniff
32
-{
31
+class NewShortTernarySniff extends Sniff {
33 32
 
34 33
     /**
35 34
      * Returns an array of tokens this test wants to listen for.
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(\T_INLINE_THEN);
42 40
     }
43 41
 
@@ -50,8 +48,7 @@  discard block
 block discarded – undo
50 48
      *
51 49
      * @return void
52 50
      */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
51
+    public function process(File $phpcsFile, $stackPtr) {
55 52
         if ($this->supportsBelow('5.2') === false) {
56 53
             return;
57 54
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
     /**
32 32
      * Returns an array of tokens this test wants to listen for.
33 33
      *
34
-     * @return array
34
+     * @return string[]
35 35
      */
36 36
     public function register()
37 37
     {
Please login to merge, or discard this patch.