@@ -29,56 +29,56 @@ |
||
29 | 29 | class NewEmptyNonVariableSniff extends Sniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function register() |
|
38 | - { |
|
39 | - return array(\T_EMPTY); |
|
40 | - } |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function register() |
|
38 | + { |
|
39 | + return array(\T_EMPTY); |
|
40 | + } |
|
41 | 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('5.4') === false) { |
|
54 | - return; |
|
55 | - } |
|
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('5.4') === false) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $tokens = $phpcsFile->getTokens(); |
|
57 | + $tokens = $phpcsFile->getTokens(); |
|
58 | 58 | |
59 | - $open = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
60 | - if ($open === false |
|
61 | - || $tokens[$open]['code'] !== \T_OPEN_PARENTHESIS |
|
62 | - || isset($tokens[$open]['parenthesis_closer']) === false |
|
63 | - ) { |
|
64 | - return; |
|
65 | - } |
|
59 | + $open = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
60 | + if ($open === false |
|
61 | + || $tokens[$open]['code'] !== \T_OPEN_PARENTHESIS |
|
62 | + || isset($tokens[$open]['parenthesis_closer']) === false |
|
63 | + ) { |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - $close = $tokens[$open]['parenthesis_closer']; |
|
67 | + $close = $tokens[$open]['parenthesis_closer']; |
|
68 | 68 | |
69 | - $nestingLevel = 0; |
|
70 | - if ($close !== ($open + 1) && isset($tokens[$open + 1]['nested_parenthesis'])) { |
|
71 | - $nestingLevel = \count($tokens[$open + 1]['nested_parenthesis']); |
|
72 | - } |
|
69 | + $nestingLevel = 0; |
|
70 | + if ($close !== ($open + 1) && isset($tokens[$open + 1]['nested_parenthesis'])) { |
|
71 | + $nestingLevel = \count($tokens[$open + 1]['nested_parenthesis']); |
|
72 | + } |
|
73 | 73 | |
74 | - if ($this->isVariable($phpcsFile, ($open + 1), $close, $nestingLevel) === true) { |
|
75 | - return; |
|
76 | - } |
|
74 | + if ($this->isVariable($phpcsFile, ($open + 1), $close, $nestingLevel) === true) { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - $phpcsFile->addError( |
|
79 | - 'Only variables can be passed to empty() prior to PHP 5.5.', |
|
80 | - $stackPtr, |
|
81 | - 'Found' |
|
82 | - ); |
|
83 | - } |
|
78 | + $phpcsFile->addError( |
|
79 | + 'Only variables can be passed to empty() prior to PHP 5.5.', |
|
80 | + $stackPtr, |
|
81 | + 'Found' |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function register() |
38 | 38 | { |
39 | - return array(\T_EMPTY); |
|
39 | + return array( \T_EMPTY ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,30 +48,30 @@ discard block |
||
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('5.4') === false) { |
|
53 | + if ( $this->supportsBelow( '5.4' ) === false ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $tokens = $phpcsFile->getTokens(); |
58 | 58 | |
59 | - $open = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
60 | - if ($open === false |
|
61 | - || $tokens[$open]['code'] !== \T_OPEN_PARENTHESIS |
|
62 | - || isset($tokens[$open]['parenthesis_closer']) === false |
|
59 | + $open = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
60 | + if ( $open === false |
|
61 | + || $tokens[ $open ][ 'code' ] !== \T_OPEN_PARENTHESIS |
|
62 | + || isset( $tokens[ $open ][ 'parenthesis_closer' ] ) === false |
|
63 | 63 | ) { |
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - $close = $tokens[$open]['parenthesis_closer']; |
|
67 | + $close = $tokens[ $open ][ 'parenthesis_closer' ]; |
|
68 | 68 | |
69 | 69 | $nestingLevel = 0; |
70 | - if ($close !== ($open + 1) && isset($tokens[$open + 1]['nested_parenthesis'])) { |
|
71 | - $nestingLevel = \count($tokens[$open + 1]['nested_parenthesis']); |
|
70 | + if ( $close !== ( $open + 1 ) && isset( $tokens[ $open + 1 ][ 'nested_parenthesis' ] ) ) { |
|
71 | + $nestingLevel = \count( $tokens[ $open + 1 ][ 'nested_parenthesis' ] ); |
|
72 | 72 | } |
73 | 73 | |
74 | - if ($this->isVariable($phpcsFile, ($open + 1), $close, $nestingLevel) === true) { |
|
74 | + if ( $this->isVariable( $phpcsFile, ( $open + 1 ), $close, $nestingLevel ) === true ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 |
@@ -26,16 +26,14 @@ discard block |
||
26 | 26 | * @package PHPCompatibility |
27 | 27 | * @author Juliette Reinders Folmer <[email protected]> |
28 | 28 | */ |
29 | -class NewEmptyNonVariableSniff extends Sniff |
|
30 | -{ |
|
29 | +class NewEmptyNonVariableSniff extends Sniff { |
|
31 | 30 | |
32 | 31 | /** |
33 | 32 | * Returns an array of tokens this test wants to listen for. |
34 | 33 | * |
35 | 34 | * @return array |
36 | 35 | */ |
37 | - public function register() |
|
38 | - { |
|
36 | + public function register() { |
|
39 | 37 | return array(\T_EMPTY); |
40 | 38 | } |
41 | 39 | |
@@ -48,8 +46,7 @@ discard block |
||
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('5.4') === false) { |
54 | 51 | return; |
55 | 52 | } |
@@ -65,7 +65,7 @@ |
||
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 | { |
@@ -24,117 +24,117 @@ |
||
24 | 24 | class NewLanguageConstructsSniff extends AbstractNewFeatureSniff |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * A list of new language constructs, not present in older versions. |
|
29 | - * |
|
30 | - * The array lists : version number with false (not present) or true (present). |
|
31 | - * If's sufficient to list the first version where the keyword appears. |
|
32 | - * |
|
33 | - * @var array(string => array(string => int|string|null)) |
|
34 | - */ |
|
35 | - protected $newConstructs = array( |
|
36 | - 'T_NS_SEPARATOR' => array( |
|
37 | - '5.2' => false, |
|
38 | - '5.3' => true, |
|
39 | - 'description' => 'the \ operator (for namespaces)', |
|
40 | - ), |
|
41 | - 'T_ELLIPSIS' => array( |
|
42 | - '5.5' => false, |
|
43 | - '5.6' => true, |
|
44 | - 'description' => 'the ... spread operator', |
|
45 | - ), |
|
46 | - ); |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Returns an array of tokens this test wants to listen for. |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function register() |
|
55 | - { |
|
56 | - $tokens = array(); |
|
57 | - foreach ($this->newConstructs as $token => $versions) { |
|
58 | - $tokens[] = constant($token); |
|
59 | - } |
|
60 | - return $tokens; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Processes this test, when one of its tokens is encountered. |
|
66 | - * |
|
67 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
68 | - * @param int $stackPtr The position of the current token in |
|
69 | - * the stack passed in $tokens. |
|
70 | - * |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function process(File $phpcsFile, $stackPtr) |
|
74 | - { |
|
75 | - $tokens = $phpcsFile->getTokens(); |
|
76 | - $tokenType = $tokens[$stackPtr]['type']; |
|
77 | - |
|
78 | - $itemInfo = array( |
|
79 | - 'name' => $tokenType, |
|
80 | - ); |
|
81 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
87 | - * |
|
88 | - * @param array $itemInfo Base information about the item. |
|
89 | - * |
|
90 | - * @return array Version and other information about the item. |
|
91 | - */ |
|
92 | - public function getItemArray(array $itemInfo) |
|
93 | - { |
|
94 | - return $this->newConstructs[$itemInfo['name']]; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
100 | - * |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - protected function getNonVersionArrayKeys() |
|
104 | - { |
|
105 | - return array('description'); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
111 | - * |
|
112 | - * @param array $itemArray Version and other information about the item. |
|
113 | - * @param array $itemInfo Base information about the item. |
|
114 | - * |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
118 | - { |
|
119 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
120 | - $errorInfo['description'] = $itemArray['description']; |
|
121 | - |
|
122 | - return $errorInfo; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
|
128 | - * |
|
129 | - * @param array $data The error data array which was created. |
|
130 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
131 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
132 | - * |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
136 | - { |
|
137 | - $data[0] = $errorInfo['description']; |
|
138 | - return $data; |
|
139 | - } |
|
27 | + /** |
|
28 | + * A list of new language constructs, not present in older versions. |
|
29 | + * |
|
30 | + * The array lists : version number with false (not present) or true (present). |
|
31 | + * If's sufficient to list the first version where the keyword appears. |
|
32 | + * |
|
33 | + * @var array(string => array(string => int|string|null)) |
|
34 | + */ |
|
35 | + protected $newConstructs = array( |
|
36 | + 'T_NS_SEPARATOR' => array( |
|
37 | + '5.2' => false, |
|
38 | + '5.3' => true, |
|
39 | + 'description' => 'the \ operator (for namespaces)', |
|
40 | + ), |
|
41 | + 'T_ELLIPSIS' => array( |
|
42 | + '5.5' => false, |
|
43 | + '5.6' => true, |
|
44 | + 'description' => 'the ... spread operator', |
|
45 | + ), |
|
46 | + ); |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Returns an array of tokens this test wants to listen for. |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function register() |
|
55 | + { |
|
56 | + $tokens = array(); |
|
57 | + foreach ($this->newConstructs as $token => $versions) { |
|
58 | + $tokens[] = constant($token); |
|
59 | + } |
|
60 | + return $tokens; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Processes this test, when one of its tokens is encountered. |
|
66 | + * |
|
67 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
68 | + * @param int $stackPtr The position of the current token in |
|
69 | + * the stack passed in $tokens. |
|
70 | + * |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function process(File $phpcsFile, $stackPtr) |
|
74 | + { |
|
75 | + $tokens = $phpcsFile->getTokens(); |
|
76 | + $tokenType = $tokens[$stackPtr]['type']; |
|
77 | + |
|
78 | + $itemInfo = array( |
|
79 | + 'name' => $tokenType, |
|
80 | + ); |
|
81 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
87 | + * |
|
88 | + * @param array $itemInfo Base information about the item. |
|
89 | + * |
|
90 | + * @return array Version and other information about the item. |
|
91 | + */ |
|
92 | + public function getItemArray(array $itemInfo) |
|
93 | + { |
|
94 | + return $this->newConstructs[$itemInfo['name']]; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
100 | + * |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + protected function getNonVersionArrayKeys() |
|
104 | + { |
|
105 | + return array('description'); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
111 | + * |
|
112 | + * @param array $itemArray Version and other information about the item. |
|
113 | + * @param array $itemInfo Base information about the item. |
|
114 | + * |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
118 | + { |
|
119 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
120 | + $errorInfo['description'] = $itemArray['description']; |
|
121 | + |
|
122 | + return $errorInfo; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
|
128 | + * |
|
129 | + * @param array $data The error data array which was created. |
|
130 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
131 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
132 | + * |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
136 | + { |
|
137 | + $data[0] = $errorInfo['description']; |
|
138 | + return $data; |
|
139 | + } |
|
140 | 140 | } |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | public function register() |
55 | 55 | { |
56 | 56 | $tokens = array(); |
57 | - foreach ($this->newConstructs as $token => $versions) { |
|
58 | - $tokens[] = constant($token); |
|
57 | + foreach ( $this->newConstructs as $token => $versions ) { |
|
58 | + $tokens[ ] = constant( $token ); |
|
59 | 59 | } |
60 | 60 | return $tokens; |
61 | 61 | } |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return void |
72 | 72 | */ |
73 | - public function process(File $phpcsFile, $stackPtr) |
|
73 | + public function process( File $phpcsFile, $stackPtr ) |
|
74 | 74 | { |
75 | 75 | $tokens = $phpcsFile->getTokens(); |
76 | - $tokenType = $tokens[$stackPtr]['type']; |
|
76 | + $tokenType = $tokens[ $stackPtr ][ 'type' ]; |
|
77 | 77 | |
78 | 78 | $itemInfo = array( |
79 | 79 | 'name' => $tokenType, |
80 | 80 | ); |
81 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
81 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return array Version and other information about the item. |
91 | 91 | */ |
92 | - public function getItemArray(array $itemInfo) |
|
92 | + public function getItemArray( array $itemInfo ) |
|
93 | 93 | { |
94 | - return $this->newConstructs[$itemInfo['name']]; |
|
94 | + return $this->newConstructs[ $itemInfo[ 'name' ] ]; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function getNonVersionArrayKeys() |
104 | 104 | { |
105 | - return array('description'); |
|
105 | + return array( 'description' ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return array |
116 | 116 | */ |
117 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
117 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
118 | 118 | { |
119 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
120 | - $errorInfo['description'] = $itemArray['description']; |
|
119 | + $errorInfo = parent::getErrorInfo( $itemArray, $itemInfo ); |
|
120 | + $errorInfo[ 'description' ] = $itemArray[ 'description' ]; |
|
121 | 121 | |
122 | 122 | return $errorInfo; |
123 | 123 | } |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return array |
134 | 134 | */ |
135 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
135 | + protected function filterErrorData( array $data, array $itemInfo, array $errorInfo ) |
|
136 | 136 | { |
137 | - $data[0] = $errorInfo['description']; |
|
137 | + $data[ 0 ] = $errorInfo[ 'description' ]; |
|
138 | 138 | return $data; |
139 | 139 | } |
140 | 140 | } |
@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | * @author Wim Godden <[email protected]> |
22 | 22 | * @copyright 2013 Cu.be Solutions bvba |
23 | 23 | */ |
24 | -class NewLanguageConstructsSniff extends AbstractNewFeatureSniff |
|
25 | -{ |
|
24 | +class NewLanguageConstructsSniff extends AbstractNewFeatureSniff { |
|
26 | 25 | |
27 | 26 | /** |
28 | 27 | * A list of new language constructs, not present in older versions. |
@@ -51,8 +50,7 @@ discard block |
||
51 | 50 | * |
52 | 51 | * @return array |
53 | 52 | */ |
54 | - public function register() |
|
55 | - { |
|
53 | + public function register() { |
|
56 | 54 | $tokens = array(); |
57 | 55 | foreach ($this->newConstructs as $token => $versions) { |
58 | 56 | $tokens[] = constant($token); |
@@ -70,8 +68,7 @@ discard block |
||
70 | 68 | * |
71 | 69 | * @return void |
72 | 70 | */ |
73 | - public function process(File $phpcsFile, $stackPtr) |
|
74 | - { |
|
71 | + public function process(File $phpcsFile, $stackPtr) { |
|
75 | 72 | $tokens = $phpcsFile->getTokens(); |
76 | 73 | $tokenType = $tokens[$stackPtr]['type']; |
77 | 74 | |
@@ -89,8 +86,7 @@ discard block |
||
89 | 86 | * |
90 | 87 | * @return array Version and other information about the item. |
91 | 88 | */ |
92 | - public function getItemArray(array $itemInfo) |
|
93 | - { |
|
89 | + public function getItemArray(array $itemInfo) { |
|
94 | 90 | return $this->newConstructs[$itemInfo['name']]; |
95 | 91 | } |
96 | 92 | |
@@ -100,8 +96,7 @@ discard block |
||
100 | 96 | * |
101 | 97 | * @return array |
102 | 98 | */ |
103 | - protected function getNonVersionArrayKeys() |
|
104 | - { |
|
99 | + protected function getNonVersionArrayKeys() { |
|
105 | 100 | return array('description'); |
106 | 101 | } |
107 | 102 | |
@@ -114,8 +109,7 @@ discard block |
||
114 | 109 | * |
115 | 110 | * @return array |
116 | 111 | */ |
117 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
118 | - { |
|
112 | + public function getErrorInfo(array $itemArray, array $itemInfo) { |
|
119 | 113 | $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
120 | 114 | $errorInfo['description'] = $itemArray['description']; |
121 | 115 | |
@@ -132,8 +126,7 @@ discard block |
||
132 | 126 | * |
133 | 127 | * @return array |
134 | 128 | */ |
135 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
136 | - { |
|
129 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) { |
|
137 | 130 | $data[0] = $errorInfo['description']; |
138 | 131 | return $data; |
139 | 132 | } |
@@ -301,7 +301,7 @@ |
||
301 | 301 | /** |
302 | 302 | * Get an array of the non-PHP-version array keys used in a sub-array. |
303 | 303 | * |
304 | - * @return array |
|
304 | + * @return string[] |
|
305 | 305 | */ |
306 | 306 | protected function getNonVersionArrayKeys() |
307 | 307 | { |
@@ -22,126 +22,126 @@ |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Determine whether an error/warning should be thrown for an item based on collected information. |
|
27 | - * |
|
28 | - * @param array $errorInfo Detail information about an item. |
|
29 | - * |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - protected function shouldThrowError(array $errorInfo) |
|
33 | - { |
|
34 | - return ($errorInfo['deprecated'] !== '' || $errorInfo['removed'] !== ''); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
40 | - * |
|
41 | - * By default, removed feature version arrays, contain an additional 'alternative' array key. |
|
42 | - * |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - protected function getNonVersionArrayKeys() |
|
46 | - { |
|
47 | - return array('alternative'); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
53 | - * |
|
54 | - * @param array $itemArray Version and other information about the item. |
|
55 | - * @param array $itemInfo Base information about the item. |
|
56 | - * |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
60 | - { |
|
61 | - $errorInfo = array( |
|
62 | - 'deprecated' => '', |
|
63 | - 'removed' => '', |
|
64 | - 'alternative' => '', |
|
65 | - 'error' => false, |
|
66 | - ); |
|
67 | - |
|
68 | - $versionArray = $this->getVersionArray($itemArray); |
|
69 | - |
|
70 | - if (empty($versionArray) === false) { |
|
71 | - foreach ($versionArray as $version => $removed) { |
|
72 | - if ($this->supportsAbove($version) === true) { |
|
73 | - if ($removed === true && $errorInfo['removed'] === '') { |
|
74 | - $errorInfo['removed'] = $version; |
|
75 | - $errorInfo['error'] = true; |
|
76 | - } elseif ($errorInfo['deprecated'] === '') { |
|
77 | - $errorInfo['deprecated'] = $version; |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - if (isset($itemArray['alternative']) === true) { |
|
84 | - $errorInfo['alternative'] = $itemArray['alternative']; |
|
85 | - } |
|
86 | - |
|
87 | - return $errorInfo; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Get the error message template for suggesting an alternative for a specific sniff. |
|
93 | - * |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - protected function getAlternativeOptionTemplate() |
|
97 | - { |
|
98 | - return '; Use %s instead'; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Generates the error or warning for this item. |
|
104 | - * |
|
105 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
106 | - * @param int $stackPtr The position of the relevant token in |
|
107 | - * the stack. |
|
108 | - * @param array $itemInfo Base information about the item. |
|
109 | - * @param array $errorInfo Array with detail (version) information |
|
110 | - * relevant to the item. |
|
111 | - * |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
115 | - { |
|
116 | - $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
117 | - $error = $this->getErrorMsgTemplate(); |
|
118 | - |
|
119 | - $errorCode = $this->stringToErrorCode($itemName); |
|
120 | - $data = array($itemName); |
|
121 | - |
|
122 | - if ($errorInfo['deprecated'] !== '') { |
|
123 | - $error .= 'deprecated since PHP %s and '; |
|
124 | - $errorCode .= 'Deprecated'; |
|
125 | - $data[] = $errorInfo['deprecated']; |
|
126 | - } |
|
127 | - |
|
128 | - if ($errorInfo['removed'] !== '') { |
|
129 | - $error .= 'removed since PHP %s and '; |
|
130 | - $errorCode .= 'Removed'; |
|
131 | - $data[] = $errorInfo['removed']; |
|
132 | - } |
|
133 | - |
|
134 | - // Remove the last 'and' from the message. |
|
135 | - $error = substr($error, 0, (\strlen($error) - 5)); |
|
136 | - |
|
137 | - if ($errorInfo['alternative'] !== '') { |
|
138 | - $error .= $this->getAlternativeOptionTemplate(); |
|
139 | - $data[] = $errorInfo['alternative']; |
|
140 | - } |
|
141 | - |
|
142 | - $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
143 | - $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
144 | - |
|
145 | - $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
146 | - } |
|
25 | + /** |
|
26 | + * Determine whether an error/warning should be thrown for an item based on collected information. |
|
27 | + * |
|
28 | + * @param array $errorInfo Detail information about an item. |
|
29 | + * |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + protected function shouldThrowError(array $errorInfo) |
|
33 | + { |
|
34 | + return ($errorInfo['deprecated'] !== '' || $errorInfo['removed'] !== ''); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
40 | + * |
|
41 | + * By default, removed feature version arrays, contain an additional 'alternative' array key. |
|
42 | + * |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + protected function getNonVersionArrayKeys() |
|
46 | + { |
|
47 | + return array('alternative'); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
53 | + * |
|
54 | + * @param array $itemArray Version and other information about the item. |
|
55 | + * @param array $itemInfo Base information about the item. |
|
56 | + * |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
60 | + { |
|
61 | + $errorInfo = array( |
|
62 | + 'deprecated' => '', |
|
63 | + 'removed' => '', |
|
64 | + 'alternative' => '', |
|
65 | + 'error' => false, |
|
66 | + ); |
|
67 | + |
|
68 | + $versionArray = $this->getVersionArray($itemArray); |
|
69 | + |
|
70 | + if (empty($versionArray) === false) { |
|
71 | + foreach ($versionArray as $version => $removed) { |
|
72 | + if ($this->supportsAbove($version) === true) { |
|
73 | + if ($removed === true && $errorInfo['removed'] === '') { |
|
74 | + $errorInfo['removed'] = $version; |
|
75 | + $errorInfo['error'] = true; |
|
76 | + } elseif ($errorInfo['deprecated'] === '') { |
|
77 | + $errorInfo['deprecated'] = $version; |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + if (isset($itemArray['alternative']) === true) { |
|
84 | + $errorInfo['alternative'] = $itemArray['alternative']; |
|
85 | + } |
|
86 | + |
|
87 | + return $errorInfo; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Get the error message template for suggesting an alternative for a specific sniff. |
|
93 | + * |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + protected function getAlternativeOptionTemplate() |
|
97 | + { |
|
98 | + return '; Use %s instead'; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Generates the error or warning for this item. |
|
104 | + * |
|
105 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
106 | + * @param int $stackPtr The position of the relevant token in |
|
107 | + * the stack. |
|
108 | + * @param array $itemInfo Base information about the item. |
|
109 | + * @param array $errorInfo Array with detail (version) information |
|
110 | + * relevant to the item. |
|
111 | + * |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
115 | + { |
|
116 | + $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
117 | + $error = $this->getErrorMsgTemplate(); |
|
118 | + |
|
119 | + $errorCode = $this->stringToErrorCode($itemName); |
|
120 | + $data = array($itemName); |
|
121 | + |
|
122 | + if ($errorInfo['deprecated'] !== '') { |
|
123 | + $error .= 'deprecated since PHP %s and '; |
|
124 | + $errorCode .= 'Deprecated'; |
|
125 | + $data[] = $errorInfo['deprecated']; |
|
126 | + } |
|
127 | + |
|
128 | + if ($errorInfo['removed'] !== '') { |
|
129 | + $error .= 'removed since PHP %s and '; |
|
130 | + $errorCode .= 'Removed'; |
|
131 | + $data[] = $errorInfo['removed']; |
|
132 | + } |
|
133 | + |
|
134 | + // Remove the last 'and' from the message. |
|
135 | + $error = substr($error, 0, (\strlen($error) - 5)); |
|
136 | + |
|
137 | + if ($errorInfo['alternative'] !== '') { |
|
138 | + $error .= $this->getAlternativeOptionTemplate(); |
|
139 | + $data[] = $errorInfo['alternative']; |
|
140 | + } |
|
141 | + |
|
142 | + $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
143 | + $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
144 | + |
|
145 | + $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
146 | + } |
|
147 | 147 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - protected function shouldThrowError(array $errorInfo) |
|
32 | + protected function shouldThrowError( array $errorInfo ) |
|
33 | 33 | { |
34 | - return ($errorInfo['deprecated'] !== '' || $errorInfo['removed'] !== ''); |
|
34 | + return ( $errorInfo[ 'deprecated' ] !== '' || $errorInfo[ 'removed' ] !== '' ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function getNonVersionArrayKeys() |
46 | 46 | { |
47 | - return array('alternative'); |
|
47 | + return array( 'alternative' ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return array |
58 | 58 | */ |
59 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
59 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
60 | 60 | { |
61 | 61 | $errorInfo = array( |
62 | 62 | 'deprecated' => '', |
@@ -65,23 +65,23 @@ discard block |
||
65 | 65 | 'error' => false, |
66 | 66 | ); |
67 | 67 | |
68 | - $versionArray = $this->getVersionArray($itemArray); |
|
68 | + $versionArray = $this->getVersionArray( $itemArray ); |
|
69 | 69 | |
70 | - if (empty($versionArray) === false) { |
|
71 | - foreach ($versionArray as $version => $removed) { |
|
72 | - if ($this->supportsAbove($version) === true) { |
|
73 | - if ($removed === true && $errorInfo['removed'] === '') { |
|
74 | - $errorInfo['removed'] = $version; |
|
75 | - $errorInfo['error'] = true; |
|
76 | - } elseif ($errorInfo['deprecated'] === '') { |
|
77 | - $errorInfo['deprecated'] = $version; |
|
70 | + if ( empty( $versionArray ) === false ) { |
|
71 | + foreach ( $versionArray as $version => $removed ) { |
|
72 | + if ( $this->supportsAbove( $version ) === true ) { |
|
73 | + if ( $removed === true && $errorInfo[ 'removed' ] === '' ) { |
|
74 | + $errorInfo[ 'removed' ] = $version; |
|
75 | + $errorInfo[ 'error' ] = true; |
|
76 | + } elseif ( $errorInfo[ 'deprecated' ] === '' ) { |
|
77 | + $errorInfo[ 'deprecated' ] = $version; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - if (isset($itemArray['alternative']) === true) { |
|
84 | - $errorInfo['alternative'] = $itemArray['alternative']; |
|
83 | + if ( isset( $itemArray[ 'alternative' ] ) === true ) { |
|
84 | + $errorInfo[ 'alternative' ] = $itemArray[ 'alternative' ]; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $errorInfo; |
@@ -111,37 +111,37 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return void |
113 | 113 | */ |
114 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
114 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ) |
|
115 | 115 | { |
116 | - $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
116 | + $itemName = $this->getItemName( $itemInfo, $errorInfo ); |
|
117 | 117 | $error = $this->getErrorMsgTemplate(); |
118 | 118 | |
119 | - $errorCode = $this->stringToErrorCode($itemName); |
|
120 | - $data = array($itemName); |
|
119 | + $errorCode = $this->stringToErrorCode( $itemName ); |
|
120 | + $data = array( $itemName ); |
|
121 | 121 | |
122 | - if ($errorInfo['deprecated'] !== '') { |
|
122 | + if ( $errorInfo[ 'deprecated' ] !== '' ) { |
|
123 | 123 | $error .= 'deprecated since PHP %s and '; |
124 | 124 | $errorCode .= 'Deprecated'; |
125 | - $data[] = $errorInfo['deprecated']; |
|
125 | + $data[ ] = $errorInfo[ 'deprecated' ]; |
|
126 | 126 | } |
127 | 127 | |
128 | - if ($errorInfo['removed'] !== '') { |
|
128 | + if ( $errorInfo[ 'removed' ] !== '' ) { |
|
129 | 129 | $error .= 'removed since PHP %s and '; |
130 | 130 | $errorCode .= 'Removed'; |
131 | - $data[] = $errorInfo['removed']; |
|
131 | + $data[ ] = $errorInfo[ 'removed' ]; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Remove the last 'and' from the message. |
135 | - $error = substr($error, 0, (\strlen($error) - 5)); |
|
135 | + $error = substr( $error, 0, ( \strlen( $error ) - 5 ) ); |
|
136 | 136 | |
137 | - if ($errorInfo['alternative'] !== '') { |
|
137 | + if ( $errorInfo[ 'alternative' ] !== '' ) { |
|
138 | 138 | $error .= $this->getAlternativeOptionTemplate(); |
139 | - $data[] = $errorInfo['alternative']; |
|
139 | + $data[ ] = $errorInfo[ 'alternative' ]; |
|
140 | 140 | } |
141 | 141 | |
142 | - $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
143 | - $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
142 | + $error = $this->filterErrorMsg( $error, $itemInfo, $errorInfo ); |
|
143 | + $data = $this->filterErrorData( $data, $itemInfo, $errorInfo ); |
|
144 | 144 | |
145 | - $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
145 | + $this->addMessage( $phpcsFile, $error, $stackPtr, $errorInfo[ 'error' ], $errorCode, $data ); |
|
146 | 146 | } |
147 | 147 | } |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * @package PHPCompatibility |
19 | 19 | * @author Juliette Reinders Folmer <[email protected]> |
20 | 20 | */ |
21 | -abstract class AbstractRemovedFeatureSniff extends AbstractComplexVersionSniff |
|
22 | -{ |
|
21 | +abstract class AbstractRemovedFeatureSniff extends AbstractComplexVersionSniff { |
|
23 | 22 | |
24 | 23 | |
25 | 24 | /** |
@@ -29,8 +28,7 @@ discard block |
||
29 | 28 | * |
30 | 29 | * @return bool |
31 | 30 | */ |
32 | - protected function shouldThrowError(array $errorInfo) |
|
33 | - { |
|
31 | + protected function shouldThrowError(array $errorInfo) { |
|
34 | 32 | return ($errorInfo['deprecated'] !== '' || $errorInfo['removed'] !== ''); |
35 | 33 | } |
36 | 34 | |
@@ -42,8 +40,7 @@ discard block |
||
42 | 40 | * |
43 | 41 | * @return array |
44 | 42 | */ |
45 | - protected function getNonVersionArrayKeys() |
|
46 | - { |
|
43 | + protected function getNonVersionArrayKeys() { |
|
47 | 44 | return array('alternative'); |
48 | 45 | } |
49 | 46 | |
@@ -56,8 +53,7 @@ discard block |
||
56 | 53 | * |
57 | 54 | * @return array |
58 | 55 | */ |
59 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
60 | - { |
|
56 | + public function getErrorInfo(array $itemArray, array $itemInfo) { |
|
61 | 57 | $errorInfo = array( |
62 | 58 | 'deprecated' => '', |
63 | 59 | 'removed' => '', |
@@ -93,8 +89,7 @@ discard block |
||
93 | 89 | * |
94 | 90 | * @return string |
95 | 91 | */ |
96 | - protected function getAlternativeOptionTemplate() |
|
97 | - { |
|
92 | + protected function getAlternativeOptionTemplate() { |
|
98 | 93 | return '; Use %s instead'; |
99 | 94 | } |
100 | 95 | |
@@ -111,8 +106,7 @@ discard block |
||
111 | 106 | * |
112 | 107 | * @return void |
113 | 108 | */ |
114 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
115 | - { |
|
109 | + public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) { |
|
116 | 110 | $itemName = $this->getItemName($itemInfo, $errorInfo); |
117 | 111 | $error = $this->getErrorMsgTemplate(); |
118 | 112 |
@@ -30,623 +30,623 @@ |
||
30 | 30 | class PHPCSHelper |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * Get the PHPCS version number. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public static function getVersion() |
|
39 | - { |
|
40 | - if (\defined('\PHP_CodeSniffer\Config::VERSION')) { |
|
41 | - // PHPCS 3.x. |
|
42 | - return \PHP_CodeSniffer\Config::VERSION; |
|
43 | - } else { |
|
44 | - // PHPCS 2.x. |
|
45 | - return \PHP_CodeSniffer::VERSION; |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Pass config data to PHPCS. |
|
52 | - * |
|
53 | - * PHPCS cross-version compatibility helper. |
|
54 | - * |
|
55 | - * @param string $key The name of the config value. |
|
56 | - * @param string|null $value The value to set. If null, the config entry |
|
57 | - * is deleted, reverting it to the default value. |
|
58 | - * @param boolean $temp Set this config data temporarily for this script run. |
|
59 | - * This will not write the config data to the config file. |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public static function setConfigData($key, $value, $temp = false) |
|
64 | - { |
|
65 | - if (method_exists('\PHP_CodeSniffer\Config', 'setConfigData')) { |
|
66 | - // PHPCS 3.x. |
|
67 | - \PHP_CodeSniffer\Config::setConfigData($key, $value, $temp); |
|
68 | - } else { |
|
69 | - // PHPCS 2.x. |
|
70 | - \PHP_CodeSniffer::setConfigData($key, $value, $temp); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the value of a single PHPCS config key. |
|
77 | - * |
|
78 | - * @param string $key The name of the config value. |
|
79 | - * |
|
80 | - * @return string|null |
|
81 | - */ |
|
82 | - public static function getConfigData($key) |
|
83 | - { |
|
84 | - if (method_exists('\PHP_CodeSniffer\Config', 'getConfigData')) { |
|
85 | - // PHPCS 3.x. |
|
86 | - return \PHP_CodeSniffer\Config::getConfigData($key); |
|
87 | - } else { |
|
88 | - // PHPCS 2.x. |
|
89 | - return \PHP_CodeSniffer::getConfigData($key); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Get the value of a single PHPCS config key. |
|
96 | - * |
|
97 | - * This config key can be set in the `CodeSniffer.conf` file, on the |
|
98 | - * command-line or in a ruleset. |
|
99 | - * |
|
100 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
101 | - * @param string $key The name of the config value. |
|
102 | - * |
|
103 | - * @return string|null |
|
104 | - */ |
|
105 | - public static function getCommandLineData(File $phpcsFile, $key) |
|
106 | - { |
|
107 | - if (class_exists('\PHP_CodeSniffer\Config')) { |
|
108 | - // PHPCS 3.x. |
|
109 | - $config = $phpcsFile->config; |
|
110 | - if (isset($config->{$key})) { |
|
111 | - return $config->{$key}; |
|
112 | - } |
|
113 | - } else { |
|
114 | - // PHPCS 2.x. |
|
115 | - $config = $phpcsFile->phpcs->cli->getCommandLineValues(); |
|
116 | - if (isset($config[$key])) { |
|
117 | - return $config[$key]; |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - return null; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns the position of the first non-whitespace token in a statement. |
|
127 | - * |
|
128 | - * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
129 | - * class and introduced in PHPCS 2.1.0 and improved in PHPCS 2.7.1. |
|
130 | - * |
|
131 | - * Once the minimum supported PHPCS version for this standard goes beyond |
|
132 | - * that, this method can be removed and calls to it replaced with |
|
133 | - * `$phpcsFile->findStartOfStatement($start, $ignore)` calls. |
|
134 | - * |
|
135 | - * Last synced with PHPCS version: PHPCS 3.3.2 at commit 6ad28354c04b364c3c71a34e4a18b629cc3b231e}} |
|
136 | - * |
|
137 | - * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
138 | - * @param int $start The position to start searching from in the token stack. |
|
139 | - * @param int|array $ignore Token types that should not be considered stop points. |
|
140 | - * |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - public static function findStartOfStatement(File $phpcsFile, $start, $ignore = null) |
|
144 | - { |
|
145 | - if (version_compare(self::getVersion(), '2.7.1', '>=') === true) { |
|
146 | - return $phpcsFile->findStartOfStatement($start, $ignore); |
|
147 | - } |
|
148 | - |
|
149 | - $tokens = $phpcsFile->getTokens(); |
|
150 | - $endTokens = Tokens::$blockOpeners; |
|
151 | - |
|
152 | - $endTokens[\T_COLON] = true; |
|
153 | - $endTokens[\T_COMMA] = true; |
|
154 | - $endTokens[\T_DOUBLE_ARROW] = true; |
|
155 | - $endTokens[\T_SEMICOLON] = true; |
|
156 | - $endTokens[\T_OPEN_TAG] = true; |
|
157 | - $endTokens[\T_CLOSE_TAG] = true; |
|
158 | - $endTokens[\T_OPEN_SHORT_ARRAY] = true; |
|
159 | - |
|
160 | - if ($ignore !== null) { |
|
161 | - $ignore = (array) $ignore; |
|
162 | - foreach ($ignore as $code) { |
|
163 | - if (isset($endTokens[$code]) === true) { |
|
164 | - unset($endTokens[$code]); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - $lastNotEmpty = $start; |
|
170 | - |
|
171 | - for ($i = $start; $i >= 0; $i--) { |
|
172 | - if (isset($endTokens[$tokens[$i]['code']]) === true) { |
|
173 | - // Found the end of the previous statement. |
|
174 | - return $lastNotEmpty; |
|
175 | - } |
|
176 | - |
|
177 | - if (isset($tokens[$i]['scope_opener']) === true |
|
178 | - && $i === $tokens[$i]['scope_closer'] |
|
179 | - ) { |
|
180 | - // Found the end of the previous scope block. |
|
181 | - return $lastNotEmpty; |
|
182 | - } |
|
183 | - |
|
184 | - // Skip nested statements. |
|
185 | - if (isset($tokens[$i]['bracket_opener']) === true |
|
186 | - && $i === $tokens[$i]['bracket_closer'] |
|
187 | - ) { |
|
188 | - $i = $tokens[$i]['bracket_opener']; |
|
189 | - } elseif (isset($tokens[$i]['parenthesis_opener']) === true |
|
190 | - && $i === $tokens[$i]['parenthesis_closer'] |
|
191 | - ) { |
|
192 | - $i = $tokens[$i]['parenthesis_opener']; |
|
193 | - } |
|
194 | - |
|
195 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { |
|
196 | - $lastNotEmpty = $i; |
|
197 | - } |
|
198 | - }//end for |
|
199 | - |
|
200 | - return 0; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the position of the last non-whitespace token in a statement. |
|
206 | - * |
|
207 | - * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
208 | - * class and introduced in PHPCS 2.1.0 and improved in PHPCS 2.7.1 and 3.3.0. |
|
209 | - * |
|
210 | - * Once the minimum supported PHPCS version for this standard goes beyond |
|
211 | - * that, this method can be removed and calls to it replaced with |
|
212 | - * `$phpcsFile->findEndOfStatement($start, $ignore)` calls. |
|
213 | - * |
|
214 | - * Last synced with PHPCS version: PHPCS 3.3.0-alpha at commit f5d899dcb5c534a1c3cca34668624517856ba823}} |
|
215 | - * |
|
216 | - * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
217 | - * @param int $start The position to start searching from in the token stack. |
|
218 | - * @param int|array $ignore Token types that should not be considered stop points. |
|
219 | - * |
|
220 | - * @return int |
|
221 | - */ |
|
222 | - public static function findEndOfStatement(File $phpcsFile, $start, $ignore = null) |
|
223 | - { |
|
224 | - if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
|
225 | - return $phpcsFile->findEndOfStatement($start, $ignore); |
|
226 | - } |
|
227 | - |
|
228 | - $tokens = $phpcsFile->getTokens(); |
|
229 | - $endTokens = array( |
|
230 | - \T_COLON => true, |
|
231 | - \T_COMMA => true, |
|
232 | - \T_DOUBLE_ARROW => true, |
|
233 | - \T_SEMICOLON => true, |
|
234 | - \T_CLOSE_PARENTHESIS => true, |
|
235 | - \T_CLOSE_SQUARE_BRACKET => true, |
|
236 | - \T_CLOSE_CURLY_BRACKET => true, |
|
237 | - \T_CLOSE_SHORT_ARRAY => true, |
|
238 | - \T_OPEN_TAG => true, |
|
239 | - \T_CLOSE_TAG => true, |
|
240 | - ); |
|
241 | - |
|
242 | - if ($ignore !== null) { |
|
243 | - $ignore = (array) $ignore; |
|
244 | - foreach ($ignore as $code) { |
|
245 | - if (isset($endTokens[$code]) === true) { |
|
246 | - unset($endTokens[$code]); |
|
247 | - } |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - $lastNotEmpty = $start; |
|
252 | - |
|
253 | - for ($i = $start; $i < $phpcsFile->numTokens; $i++) { |
|
254 | - if ($i !== $start && isset($endTokens[$tokens[$i]['code']]) === true) { |
|
255 | - // Found the end of the statement. |
|
256 | - if ($tokens[$i]['code'] === \T_CLOSE_PARENTHESIS |
|
257 | - || $tokens[$i]['code'] === \T_CLOSE_SQUARE_BRACKET |
|
258 | - || $tokens[$i]['code'] === \T_CLOSE_CURLY_BRACKET |
|
259 | - || $tokens[$i]['code'] === \T_CLOSE_SHORT_ARRAY |
|
260 | - || $tokens[$i]['code'] === \T_OPEN_TAG |
|
261 | - || $tokens[$i]['code'] === \T_CLOSE_TAG |
|
262 | - ) { |
|
263 | - return $lastNotEmpty; |
|
264 | - } |
|
265 | - |
|
266 | - return $i; |
|
267 | - } |
|
268 | - |
|
269 | - // Skip nested statements. |
|
270 | - if (isset($tokens[$i]['scope_closer']) === true |
|
271 | - && ($i === $tokens[$i]['scope_opener'] |
|
272 | - || $i === $tokens[$i]['scope_condition']) |
|
273 | - ) { |
|
274 | - if ($i === $start && isset(Tokens::$scopeOpeners[$tokens[$i]['code']]) === true) { |
|
275 | - return $tokens[$i]['scope_closer']; |
|
276 | - } |
|
277 | - |
|
278 | - $i = $tokens[$i]['scope_closer']; |
|
279 | - } elseif (isset($tokens[$i]['bracket_closer']) === true |
|
280 | - && $i === $tokens[$i]['bracket_opener'] |
|
281 | - ) { |
|
282 | - $i = $tokens[$i]['bracket_closer']; |
|
283 | - } elseif (isset($tokens[$i]['parenthesis_closer']) === true |
|
284 | - && $i === $tokens[$i]['parenthesis_opener'] |
|
285 | - ) { |
|
286 | - $i = $tokens[$i]['parenthesis_closer']; |
|
287 | - } |
|
288 | - |
|
289 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { |
|
290 | - $lastNotEmpty = $i; |
|
291 | - } |
|
292 | - }//end for |
|
293 | - |
|
294 | - return ($phpcsFile->numTokens - 1); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the name of the class that the specified class extends |
|
300 | - * (works for classes, anonymous classes and interfaces). |
|
301 | - * |
|
302 | - * Returns FALSE on error or if there is no extended class name. |
|
303 | - * |
|
304 | - * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
305 | - * class, but with some improvements which have been introduced in |
|
306 | - * PHPCS 2.8.0. |
|
307 | - * {@link https://github.com/squizlabs/PHP_CodeSniffer/commit/0011d448119d4c568e3ac1f825ae78815bf2cc34}. |
|
308 | - * |
|
309 | - * Once the minimum supported PHPCS version for this standard goes beyond |
|
310 | - * that, this method can be removed and calls to it replaced with |
|
311 | - * `$phpcsFile->findExtendedClassName($stackPtr)` calls. |
|
312 | - * |
|
313 | - * Last synced with PHPCS version: PHPCS 3.1.0-alpha at commit a9efcc9b0703f3f9f4a900623d4e97128a6aafc6}} |
|
314 | - * |
|
315 | - * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
316 | - * @param int $stackPtr The position of the class token in the stack. |
|
317 | - * |
|
318 | - * @return string|false |
|
319 | - */ |
|
320 | - public static function findExtendedClassName(File $phpcsFile, $stackPtr) |
|
321 | - { |
|
322 | - if (version_compare(self::getVersion(), '3.1.0', '>=') === true) { |
|
323 | - return $phpcsFile->findExtendedClassName($stackPtr); |
|
324 | - } |
|
325 | - |
|
326 | - $tokens = $phpcsFile->getTokens(); |
|
327 | - |
|
328 | - // Check for the existence of the token. |
|
329 | - if (isset($tokens[$stackPtr]) === false) { |
|
330 | - return false; |
|
331 | - } |
|
332 | - |
|
333 | - if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
334 | - && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
335 | - && $tokens[$stackPtr]['type'] !== 'T_INTERFACE' |
|
336 | - ) { |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
341 | - return false; |
|
342 | - } |
|
343 | - |
|
344 | - $classCloserIndex = $tokens[$stackPtr]['scope_closer']; |
|
345 | - $extendsIndex = $phpcsFile->findNext(\T_EXTENDS, $stackPtr, $classCloserIndex); |
|
346 | - if ($extendsIndex === false) { |
|
347 | - return false; |
|
348 | - } |
|
349 | - |
|
350 | - $find = array( |
|
351 | - \T_NS_SEPARATOR, |
|
352 | - \T_STRING, |
|
353 | - \T_WHITESPACE, |
|
354 | - ); |
|
355 | - |
|
356 | - $end = $phpcsFile->findNext($find, ($extendsIndex + 1), $classCloserIndex, true); |
|
357 | - $name = $phpcsFile->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1)); |
|
358 | - $name = trim($name); |
|
359 | - |
|
360 | - if ($name === '') { |
|
361 | - return false; |
|
362 | - } |
|
363 | - |
|
364 | - return $name; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Returns the name(s) of the interface(s) that the specified class implements. |
|
370 | - * |
|
371 | - * Returns FALSE on error or if there are no implemented interface names. |
|
372 | - * |
|
373 | - * {@internal Duplicate of same method as introduced in PHPCS 2.7. |
|
374 | - * This method also includes an improvement we use which was only introduced |
|
375 | - * in PHPCS 2.8.0, so only defer to upstream for higher versions. |
|
376 | - * Once the minimum supported PHPCS version for this sniff library goes beyond |
|
377 | - * that, this method can be removed and calls to it replaced with |
|
378 | - * `$phpcsFile->findImplementedInterfaceNames($stackPtr)` calls.}} |
|
379 | - * |
|
380 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
381 | - * @param int $stackPtr The position of the class token. |
|
382 | - * |
|
383 | - * @return array|false |
|
384 | - */ |
|
385 | - public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) |
|
386 | - { |
|
387 | - if (version_compare(self::getVersion(), '2.7.1', '>') === true) { |
|
388 | - return $phpcsFile->findImplementedInterfaceNames($stackPtr); |
|
389 | - } |
|
390 | - |
|
391 | - $tokens = $phpcsFile->getTokens(); |
|
392 | - |
|
393 | - // Check for the existence of the token. |
|
394 | - if (isset($tokens[$stackPtr]) === false) { |
|
395 | - return false; |
|
396 | - } |
|
397 | - |
|
398 | - if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
399 | - && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
400 | - ) { |
|
401 | - return false; |
|
402 | - } |
|
403 | - |
|
404 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
405 | - return false; |
|
406 | - } |
|
407 | - |
|
408 | - $classOpenerIndex = $tokens[$stackPtr]['scope_opener']; |
|
409 | - $implementsIndex = $phpcsFile->findNext(\T_IMPLEMENTS, $stackPtr, $classOpenerIndex); |
|
410 | - if ($implementsIndex === false) { |
|
411 | - return false; |
|
412 | - } |
|
413 | - |
|
414 | - $find = array( |
|
415 | - \T_NS_SEPARATOR, |
|
416 | - \T_STRING, |
|
417 | - \T_WHITESPACE, |
|
418 | - \T_COMMA, |
|
419 | - ); |
|
420 | - |
|
421 | - $end = $phpcsFile->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true); |
|
422 | - $name = $phpcsFile->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1)); |
|
423 | - $name = trim($name); |
|
424 | - |
|
425 | - if ($name === '') { |
|
426 | - return false; |
|
427 | - } else { |
|
428 | - $names = explode(',', $name); |
|
429 | - $names = array_map('trim', $names); |
|
430 | - return $names; |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Returns the method parameters for the specified function token. |
|
437 | - * |
|
438 | - * Each parameter is in the following format: |
|
439 | - * |
|
440 | - * <code> |
|
441 | - * 0 => array( |
|
442 | - * 'name' => '$var', // The variable name. |
|
443 | - * 'token' => integer, // The stack pointer to the variable name. |
|
444 | - * 'content' => string, // The full content of the variable definition. |
|
445 | - * 'pass_by_reference' => boolean, // Is the variable passed by reference? |
|
446 | - * 'variable_length' => boolean, // Is the param of variable length through use of `...` ? |
|
447 | - * 'type_hint' => string, // The type hint for the variable. |
|
448 | - * 'type_hint_token' => integer, // The stack pointer to the type hint |
|
449 | - * // or false if there is no type hint. |
|
450 | - * 'nullable_type' => boolean, // Is the variable using a nullable type? |
|
451 | - * ) |
|
452 | - * </code> |
|
453 | - * |
|
454 | - * Parameters with default values have an additional array index of |
|
455 | - * 'default' with the value of the default as a string. |
|
456 | - * |
|
457 | - * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
458 | - * class. |
|
459 | - * |
|
460 | - * Last synced with PHPCS version: PHPCS 3.3.0-alpha at commit 53a28408d345044c0360c2c1b4a2aaebf4a3b8c9}} |
|
461 | - * |
|
462 | - * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
463 | - * @param int $stackPtr The position in the stack of the |
|
464 | - * function token to acquire the |
|
465 | - * parameters for. |
|
466 | - * |
|
467 | - * @return array|false |
|
468 | - * @throws \PHP_CodeSniffer_Exception If the specified $stackPtr is not of |
|
469 | - * type T_FUNCTION or T_CLOSURE. |
|
470 | - */ |
|
471 | - public static function getMethodParameters(File $phpcsFile, $stackPtr) |
|
472 | - { |
|
473 | - if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
|
474 | - return $phpcsFile->getMethodParameters($stackPtr); |
|
475 | - } |
|
476 | - |
|
477 | - $tokens = $phpcsFile->getTokens(); |
|
478 | - |
|
479 | - // Check for the existence of the token. |
|
480 | - if (isset($tokens[$stackPtr]) === false) { |
|
481 | - return false; |
|
482 | - } |
|
483 | - |
|
484 | - if ($tokens[$stackPtr]['code'] !== \T_FUNCTION |
|
485 | - && $tokens[$stackPtr]['code'] !== \T_CLOSURE |
|
486 | - ) { |
|
487 | - throw new PHPCS_Exception('$stackPtr must be of type T_FUNCTION or T_CLOSURE'); |
|
488 | - } |
|
489 | - |
|
490 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
491 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
492 | - |
|
493 | - $vars = array(); |
|
494 | - $currVar = null; |
|
495 | - $paramStart = ($opener + 1); |
|
496 | - $defaultStart = null; |
|
497 | - $paramCount = 0; |
|
498 | - $passByReference = false; |
|
499 | - $variableLength = false; |
|
500 | - $typeHint = ''; |
|
501 | - $typeHintToken = false; |
|
502 | - $nullableType = false; |
|
503 | - |
|
504 | - for ($i = $paramStart; $i <= $closer; $i++) { |
|
505 | - // Check to see if this token has a parenthesis or bracket opener. If it does |
|
506 | - // it's likely to be an array which might have arguments in it. This |
|
507 | - // could cause problems in our parsing below, so lets just skip to the |
|
508 | - // end of it. |
|
509 | - if (isset($tokens[$i]['parenthesis_opener']) === true) { |
|
510 | - // Don't do this if it's the close parenthesis for the method. |
|
511 | - if ($i !== $tokens[$i]['parenthesis_closer']) { |
|
512 | - $i = ($tokens[$i]['parenthesis_closer'] + 1); |
|
513 | - } |
|
514 | - } |
|
515 | - |
|
516 | - if (isset($tokens[$i]['bracket_opener']) === true) { |
|
517 | - // Don't do this if it's the close parenthesis for the method. |
|
518 | - if ($i !== $tokens[$i]['bracket_closer']) { |
|
519 | - $i = ($tokens[$i]['bracket_closer'] + 1); |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - switch ($tokens[$i]['type']) { |
|
524 | - case 'T_BITWISE_AND': |
|
525 | - if ($defaultStart === null) { |
|
526 | - $passByReference = true; |
|
527 | - } |
|
528 | - break; |
|
529 | - case 'T_VARIABLE': |
|
530 | - $currVar = $i; |
|
531 | - break; |
|
532 | - case 'T_ELLIPSIS': |
|
533 | - $variableLength = true; |
|
534 | - break; |
|
535 | - case 'T_ARRAY_HINT': // Pre-PHPCS 3.3.0. |
|
536 | - case 'T_CALLABLE': |
|
537 | - if ($typeHintToken === false) { |
|
538 | - $typeHintToken = $i; |
|
539 | - } |
|
540 | - |
|
541 | - $typeHint .= $tokens[$i]['content']; |
|
542 | - break; |
|
543 | - case 'T_SELF': |
|
544 | - case 'T_PARENT': |
|
545 | - case 'T_STATIC': |
|
546 | - // Self and parent are valid, static invalid, but was probably intended as type hint. |
|
547 | - if (isset($defaultStart) === false) { |
|
548 | - if ($typeHintToken === false) { |
|
549 | - $typeHintToken = $i; |
|
550 | - } |
|
551 | - |
|
552 | - $typeHint .= $tokens[$i]['content']; |
|
553 | - } |
|
554 | - break; |
|
555 | - case 'T_STRING': |
|
556 | - // This is a string, so it may be a type hint, but it could |
|
557 | - // also be a constant used as a default value. |
|
558 | - $prevComma = false; |
|
559 | - for ($t = $i; $t >= $opener; $t--) { |
|
560 | - if ($tokens[$t]['code'] === \T_COMMA) { |
|
561 | - $prevComma = $t; |
|
562 | - break; |
|
563 | - } |
|
564 | - } |
|
565 | - |
|
566 | - if ($prevComma !== false) { |
|
567 | - $nextEquals = false; |
|
568 | - for ($t = $prevComma; $t < $i; $t++) { |
|
569 | - if ($tokens[$t]['code'] === \T_EQUAL) { |
|
570 | - $nextEquals = $t; |
|
571 | - break; |
|
572 | - } |
|
573 | - } |
|
574 | - |
|
575 | - if ($nextEquals !== false) { |
|
576 | - break; |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - if ($defaultStart === null) { |
|
581 | - if ($typeHintToken === false) { |
|
582 | - $typeHintToken = $i; |
|
583 | - } |
|
584 | - |
|
585 | - $typeHint .= $tokens[$i]['content']; |
|
586 | - } |
|
587 | - break; |
|
588 | - case 'T_NS_SEPARATOR': |
|
589 | - // Part of a type hint or default value. |
|
590 | - if ($defaultStart === null) { |
|
591 | - if ($typeHintToken === false) { |
|
592 | - $typeHintToken = $i; |
|
593 | - } |
|
594 | - |
|
595 | - $typeHint .= $tokens[$i]['content']; |
|
596 | - } |
|
597 | - break; |
|
598 | - case 'T_NULLABLE': |
|
599 | - case 'T_INLINE_THEN': // Pre-PHPCS 2.8.0. |
|
600 | - if ($defaultStart === null) { |
|
601 | - $nullableType = true; |
|
602 | - $typeHint .= $tokens[$i]['content']; |
|
603 | - } |
|
604 | - break; |
|
605 | - case 'T_CLOSE_PARENTHESIS': |
|
606 | - case 'T_COMMA': |
|
607 | - // If it's null, then there must be no parameters for this |
|
608 | - // method. |
|
609 | - if ($currVar === null) { |
|
610 | - break; |
|
611 | - } |
|
612 | - |
|
613 | - $vars[$paramCount] = array(); |
|
614 | - $vars[$paramCount]['token'] = $currVar; |
|
615 | - $vars[$paramCount]['name'] = $tokens[$currVar]['content']; |
|
616 | - $vars[$paramCount]['content'] = trim($phpcsFile->getTokensAsString($paramStart, ($i - $paramStart))); |
|
617 | - |
|
618 | - if ($defaultStart !== null) { |
|
619 | - $vars[$paramCount]['default'] = trim( |
|
620 | - $phpcsFile->getTokensAsString( |
|
621 | - $defaultStart, |
|
622 | - ($i - $defaultStart) |
|
623 | - ) |
|
624 | - ); |
|
625 | - } |
|
626 | - |
|
627 | - $vars[$paramCount]['pass_by_reference'] = $passByReference; |
|
628 | - $vars[$paramCount]['variable_length'] = $variableLength; |
|
629 | - $vars[$paramCount]['type_hint'] = $typeHint; |
|
630 | - $vars[$paramCount]['type_hint_token'] = $typeHintToken; |
|
631 | - $vars[$paramCount]['nullable_type'] = $nullableType; |
|
632 | - |
|
633 | - // Reset the vars, as we are about to process the next parameter. |
|
634 | - $defaultStart = null; |
|
635 | - $paramStart = ($i + 1); |
|
636 | - $passByReference = false; |
|
637 | - $variableLength = false; |
|
638 | - $typeHint = ''; |
|
639 | - $typeHintToken = false; |
|
640 | - $nullableType = false; |
|
641 | - |
|
642 | - $paramCount++; |
|
643 | - break; |
|
644 | - case 'T_EQUAL': |
|
645 | - $defaultStart = ($i + 1); |
|
646 | - break; |
|
647 | - }//end switch |
|
648 | - }//end for |
|
649 | - |
|
650 | - return $vars; |
|
651 | - } |
|
33 | + /** |
|
34 | + * Get the PHPCS version number. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public static function getVersion() |
|
39 | + { |
|
40 | + if (\defined('\PHP_CodeSniffer\Config::VERSION')) { |
|
41 | + // PHPCS 3.x. |
|
42 | + return \PHP_CodeSniffer\Config::VERSION; |
|
43 | + } else { |
|
44 | + // PHPCS 2.x. |
|
45 | + return \PHP_CodeSniffer::VERSION; |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Pass config data to PHPCS. |
|
52 | + * |
|
53 | + * PHPCS cross-version compatibility helper. |
|
54 | + * |
|
55 | + * @param string $key The name of the config value. |
|
56 | + * @param string|null $value The value to set. If null, the config entry |
|
57 | + * is deleted, reverting it to the default value. |
|
58 | + * @param boolean $temp Set this config data temporarily for this script run. |
|
59 | + * This will not write the config data to the config file. |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public static function setConfigData($key, $value, $temp = false) |
|
64 | + { |
|
65 | + if (method_exists('\PHP_CodeSniffer\Config', 'setConfigData')) { |
|
66 | + // PHPCS 3.x. |
|
67 | + \PHP_CodeSniffer\Config::setConfigData($key, $value, $temp); |
|
68 | + } else { |
|
69 | + // PHPCS 2.x. |
|
70 | + \PHP_CodeSniffer::setConfigData($key, $value, $temp); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the value of a single PHPCS config key. |
|
77 | + * |
|
78 | + * @param string $key The name of the config value. |
|
79 | + * |
|
80 | + * @return string|null |
|
81 | + */ |
|
82 | + public static function getConfigData($key) |
|
83 | + { |
|
84 | + if (method_exists('\PHP_CodeSniffer\Config', 'getConfigData')) { |
|
85 | + // PHPCS 3.x. |
|
86 | + return \PHP_CodeSniffer\Config::getConfigData($key); |
|
87 | + } else { |
|
88 | + // PHPCS 2.x. |
|
89 | + return \PHP_CodeSniffer::getConfigData($key); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Get the value of a single PHPCS config key. |
|
96 | + * |
|
97 | + * This config key can be set in the `CodeSniffer.conf` file, on the |
|
98 | + * command-line or in a ruleset. |
|
99 | + * |
|
100 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
101 | + * @param string $key The name of the config value. |
|
102 | + * |
|
103 | + * @return string|null |
|
104 | + */ |
|
105 | + public static function getCommandLineData(File $phpcsFile, $key) |
|
106 | + { |
|
107 | + if (class_exists('\PHP_CodeSniffer\Config')) { |
|
108 | + // PHPCS 3.x. |
|
109 | + $config = $phpcsFile->config; |
|
110 | + if (isset($config->{$key})) { |
|
111 | + return $config->{$key}; |
|
112 | + } |
|
113 | + } else { |
|
114 | + // PHPCS 2.x. |
|
115 | + $config = $phpcsFile->phpcs->cli->getCommandLineValues(); |
|
116 | + if (isset($config[$key])) { |
|
117 | + return $config[$key]; |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + return null; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns the position of the first non-whitespace token in a statement. |
|
127 | + * |
|
128 | + * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
129 | + * class and introduced in PHPCS 2.1.0 and improved in PHPCS 2.7.1. |
|
130 | + * |
|
131 | + * Once the minimum supported PHPCS version for this standard goes beyond |
|
132 | + * that, this method can be removed and calls to it replaced with |
|
133 | + * `$phpcsFile->findStartOfStatement($start, $ignore)` calls. |
|
134 | + * |
|
135 | + * Last synced with PHPCS version: PHPCS 3.3.2 at commit 6ad28354c04b364c3c71a34e4a18b629cc3b231e}} |
|
136 | + * |
|
137 | + * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
138 | + * @param int $start The position to start searching from in the token stack. |
|
139 | + * @param int|array $ignore Token types that should not be considered stop points. |
|
140 | + * |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + public static function findStartOfStatement(File $phpcsFile, $start, $ignore = null) |
|
144 | + { |
|
145 | + if (version_compare(self::getVersion(), '2.7.1', '>=') === true) { |
|
146 | + return $phpcsFile->findStartOfStatement($start, $ignore); |
|
147 | + } |
|
148 | + |
|
149 | + $tokens = $phpcsFile->getTokens(); |
|
150 | + $endTokens = Tokens::$blockOpeners; |
|
151 | + |
|
152 | + $endTokens[\T_COLON] = true; |
|
153 | + $endTokens[\T_COMMA] = true; |
|
154 | + $endTokens[\T_DOUBLE_ARROW] = true; |
|
155 | + $endTokens[\T_SEMICOLON] = true; |
|
156 | + $endTokens[\T_OPEN_TAG] = true; |
|
157 | + $endTokens[\T_CLOSE_TAG] = true; |
|
158 | + $endTokens[\T_OPEN_SHORT_ARRAY] = true; |
|
159 | + |
|
160 | + if ($ignore !== null) { |
|
161 | + $ignore = (array) $ignore; |
|
162 | + foreach ($ignore as $code) { |
|
163 | + if (isset($endTokens[$code]) === true) { |
|
164 | + unset($endTokens[$code]); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + $lastNotEmpty = $start; |
|
170 | + |
|
171 | + for ($i = $start; $i >= 0; $i--) { |
|
172 | + if (isset($endTokens[$tokens[$i]['code']]) === true) { |
|
173 | + // Found the end of the previous statement. |
|
174 | + return $lastNotEmpty; |
|
175 | + } |
|
176 | + |
|
177 | + if (isset($tokens[$i]['scope_opener']) === true |
|
178 | + && $i === $tokens[$i]['scope_closer'] |
|
179 | + ) { |
|
180 | + // Found the end of the previous scope block. |
|
181 | + return $lastNotEmpty; |
|
182 | + } |
|
183 | + |
|
184 | + // Skip nested statements. |
|
185 | + if (isset($tokens[$i]['bracket_opener']) === true |
|
186 | + && $i === $tokens[$i]['bracket_closer'] |
|
187 | + ) { |
|
188 | + $i = $tokens[$i]['bracket_opener']; |
|
189 | + } elseif (isset($tokens[$i]['parenthesis_opener']) === true |
|
190 | + && $i === $tokens[$i]['parenthesis_closer'] |
|
191 | + ) { |
|
192 | + $i = $tokens[$i]['parenthesis_opener']; |
|
193 | + } |
|
194 | + |
|
195 | + if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { |
|
196 | + $lastNotEmpty = $i; |
|
197 | + } |
|
198 | + }//end for |
|
199 | + |
|
200 | + return 0; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the position of the last non-whitespace token in a statement. |
|
206 | + * |
|
207 | + * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
208 | + * class and introduced in PHPCS 2.1.0 and improved in PHPCS 2.7.1 and 3.3.0. |
|
209 | + * |
|
210 | + * Once the minimum supported PHPCS version for this standard goes beyond |
|
211 | + * that, this method can be removed and calls to it replaced with |
|
212 | + * `$phpcsFile->findEndOfStatement($start, $ignore)` calls. |
|
213 | + * |
|
214 | + * Last synced with PHPCS version: PHPCS 3.3.0-alpha at commit f5d899dcb5c534a1c3cca34668624517856ba823}} |
|
215 | + * |
|
216 | + * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
217 | + * @param int $start The position to start searching from in the token stack. |
|
218 | + * @param int|array $ignore Token types that should not be considered stop points. |
|
219 | + * |
|
220 | + * @return int |
|
221 | + */ |
|
222 | + public static function findEndOfStatement(File $phpcsFile, $start, $ignore = null) |
|
223 | + { |
|
224 | + if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
|
225 | + return $phpcsFile->findEndOfStatement($start, $ignore); |
|
226 | + } |
|
227 | + |
|
228 | + $tokens = $phpcsFile->getTokens(); |
|
229 | + $endTokens = array( |
|
230 | + \T_COLON => true, |
|
231 | + \T_COMMA => true, |
|
232 | + \T_DOUBLE_ARROW => true, |
|
233 | + \T_SEMICOLON => true, |
|
234 | + \T_CLOSE_PARENTHESIS => true, |
|
235 | + \T_CLOSE_SQUARE_BRACKET => true, |
|
236 | + \T_CLOSE_CURLY_BRACKET => true, |
|
237 | + \T_CLOSE_SHORT_ARRAY => true, |
|
238 | + \T_OPEN_TAG => true, |
|
239 | + \T_CLOSE_TAG => true, |
|
240 | + ); |
|
241 | + |
|
242 | + if ($ignore !== null) { |
|
243 | + $ignore = (array) $ignore; |
|
244 | + foreach ($ignore as $code) { |
|
245 | + if (isset($endTokens[$code]) === true) { |
|
246 | + unset($endTokens[$code]); |
|
247 | + } |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + $lastNotEmpty = $start; |
|
252 | + |
|
253 | + for ($i = $start; $i < $phpcsFile->numTokens; $i++) { |
|
254 | + if ($i !== $start && isset($endTokens[$tokens[$i]['code']]) === true) { |
|
255 | + // Found the end of the statement. |
|
256 | + if ($tokens[$i]['code'] === \T_CLOSE_PARENTHESIS |
|
257 | + || $tokens[$i]['code'] === \T_CLOSE_SQUARE_BRACKET |
|
258 | + || $tokens[$i]['code'] === \T_CLOSE_CURLY_BRACKET |
|
259 | + || $tokens[$i]['code'] === \T_CLOSE_SHORT_ARRAY |
|
260 | + || $tokens[$i]['code'] === \T_OPEN_TAG |
|
261 | + || $tokens[$i]['code'] === \T_CLOSE_TAG |
|
262 | + ) { |
|
263 | + return $lastNotEmpty; |
|
264 | + } |
|
265 | + |
|
266 | + return $i; |
|
267 | + } |
|
268 | + |
|
269 | + // Skip nested statements. |
|
270 | + if (isset($tokens[$i]['scope_closer']) === true |
|
271 | + && ($i === $tokens[$i]['scope_opener'] |
|
272 | + || $i === $tokens[$i]['scope_condition']) |
|
273 | + ) { |
|
274 | + if ($i === $start && isset(Tokens::$scopeOpeners[$tokens[$i]['code']]) === true) { |
|
275 | + return $tokens[$i]['scope_closer']; |
|
276 | + } |
|
277 | + |
|
278 | + $i = $tokens[$i]['scope_closer']; |
|
279 | + } elseif (isset($tokens[$i]['bracket_closer']) === true |
|
280 | + && $i === $tokens[$i]['bracket_opener'] |
|
281 | + ) { |
|
282 | + $i = $tokens[$i]['bracket_closer']; |
|
283 | + } elseif (isset($tokens[$i]['parenthesis_closer']) === true |
|
284 | + && $i === $tokens[$i]['parenthesis_opener'] |
|
285 | + ) { |
|
286 | + $i = $tokens[$i]['parenthesis_closer']; |
|
287 | + } |
|
288 | + |
|
289 | + if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { |
|
290 | + $lastNotEmpty = $i; |
|
291 | + } |
|
292 | + }//end for |
|
293 | + |
|
294 | + return ($phpcsFile->numTokens - 1); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the name of the class that the specified class extends |
|
300 | + * (works for classes, anonymous classes and interfaces). |
|
301 | + * |
|
302 | + * Returns FALSE on error or if there is no extended class name. |
|
303 | + * |
|
304 | + * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
305 | + * class, but with some improvements which have been introduced in |
|
306 | + * PHPCS 2.8.0. |
|
307 | + * {@link https://github.com/squizlabs/PHP_CodeSniffer/commit/0011d448119d4c568e3ac1f825ae78815bf2cc34}. |
|
308 | + * |
|
309 | + * Once the minimum supported PHPCS version for this standard goes beyond |
|
310 | + * that, this method can be removed and calls to it replaced with |
|
311 | + * `$phpcsFile->findExtendedClassName($stackPtr)` calls. |
|
312 | + * |
|
313 | + * Last synced with PHPCS version: PHPCS 3.1.0-alpha at commit a9efcc9b0703f3f9f4a900623d4e97128a6aafc6}} |
|
314 | + * |
|
315 | + * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
316 | + * @param int $stackPtr The position of the class token in the stack. |
|
317 | + * |
|
318 | + * @return string|false |
|
319 | + */ |
|
320 | + public static function findExtendedClassName(File $phpcsFile, $stackPtr) |
|
321 | + { |
|
322 | + if (version_compare(self::getVersion(), '3.1.0', '>=') === true) { |
|
323 | + return $phpcsFile->findExtendedClassName($stackPtr); |
|
324 | + } |
|
325 | + |
|
326 | + $tokens = $phpcsFile->getTokens(); |
|
327 | + |
|
328 | + // Check for the existence of the token. |
|
329 | + if (isset($tokens[$stackPtr]) === false) { |
|
330 | + return false; |
|
331 | + } |
|
332 | + |
|
333 | + if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
334 | + && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
335 | + && $tokens[$stackPtr]['type'] !== 'T_INTERFACE' |
|
336 | + ) { |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
341 | + return false; |
|
342 | + } |
|
343 | + |
|
344 | + $classCloserIndex = $tokens[$stackPtr]['scope_closer']; |
|
345 | + $extendsIndex = $phpcsFile->findNext(\T_EXTENDS, $stackPtr, $classCloserIndex); |
|
346 | + if ($extendsIndex === false) { |
|
347 | + return false; |
|
348 | + } |
|
349 | + |
|
350 | + $find = array( |
|
351 | + \T_NS_SEPARATOR, |
|
352 | + \T_STRING, |
|
353 | + \T_WHITESPACE, |
|
354 | + ); |
|
355 | + |
|
356 | + $end = $phpcsFile->findNext($find, ($extendsIndex + 1), $classCloserIndex, true); |
|
357 | + $name = $phpcsFile->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1)); |
|
358 | + $name = trim($name); |
|
359 | + |
|
360 | + if ($name === '') { |
|
361 | + return false; |
|
362 | + } |
|
363 | + |
|
364 | + return $name; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Returns the name(s) of the interface(s) that the specified class implements. |
|
370 | + * |
|
371 | + * Returns FALSE on error or if there are no implemented interface names. |
|
372 | + * |
|
373 | + * {@internal Duplicate of same method as introduced in PHPCS 2.7. |
|
374 | + * This method also includes an improvement we use which was only introduced |
|
375 | + * in PHPCS 2.8.0, so only defer to upstream for higher versions. |
|
376 | + * Once the minimum supported PHPCS version for this sniff library goes beyond |
|
377 | + * that, this method can be removed and calls to it replaced with |
|
378 | + * `$phpcsFile->findImplementedInterfaceNames($stackPtr)` calls.}} |
|
379 | + * |
|
380 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
381 | + * @param int $stackPtr The position of the class token. |
|
382 | + * |
|
383 | + * @return array|false |
|
384 | + */ |
|
385 | + public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) |
|
386 | + { |
|
387 | + if (version_compare(self::getVersion(), '2.7.1', '>') === true) { |
|
388 | + return $phpcsFile->findImplementedInterfaceNames($stackPtr); |
|
389 | + } |
|
390 | + |
|
391 | + $tokens = $phpcsFile->getTokens(); |
|
392 | + |
|
393 | + // Check for the existence of the token. |
|
394 | + if (isset($tokens[$stackPtr]) === false) { |
|
395 | + return false; |
|
396 | + } |
|
397 | + |
|
398 | + if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
399 | + && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
400 | + ) { |
|
401 | + return false; |
|
402 | + } |
|
403 | + |
|
404 | + if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
405 | + return false; |
|
406 | + } |
|
407 | + |
|
408 | + $classOpenerIndex = $tokens[$stackPtr]['scope_opener']; |
|
409 | + $implementsIndex = $phpcsFile->findNext(\T_IMPLEMENTS, $stackPtr, $classOpenerIndex); |
|
410 | + if ($implementsIndex === false) { |
|
411 | + return false; |
|
412 | + } |
|
413 | + |
|
414 | + $find = array( |
|
415 | + \T_NS_SEPARATOR, |
|
416 | + \T_STRING, |
|
417 | + \T_WHITESPACE, |
|
418 | + \T_COMMA, |
|
419 | + ); |
|
420 | + |
|
421 | + $end = $phpcsFile->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true); |
|
422 | + $name = $phpcsFile->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1)); |
|
423 | + $name = trim($name); |
|
424 | + |
|
425 | + if ($name === '') { |
|
426 | + return false; |
|
427 | + } else { |
|
428 | + $names = explode(',', $name); |
|
429 | + $names = array_map('trim', $names); |
|
430 | + return $names; |
|
431 | + } |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Returns the method parameters for the specified function token. |
|
437 | + * |
|
438 | + * Each parameter is in the following format: |
|
439 | + * |
|
440 | + * <code> |
|
441 | + * 0 => array( |
|
442 | + * 'name' => '$var', // The variable name. |
|
443 | + * 'token' => integer, // The stack pointer to the variable name. |
|
444 | + * 'content' => string, // The full content of the variable definition. |
|
445 | + * 'pass_by_reference' => boolean, // Is the variable passed by reference? |
|
446 | + * 'variable_length' => boolean, // Is the param of variable length through use of `...` ? |
|
447 | + * 'type_hint' => string, // The type hint for the variable. |
|
448 | + * 'type_hint_token' => integer, // The stack pointer to the type hint |
|
449 | + * // or false if there is no type hint. |
|
450 | + * 'nullable_type' => boolean, // Is the variable using a nullable type? |
|
451 | + * ) |
|
452 | + * </code> |
|
453 | + * |
|
454 | + * Parameters with default values have an additional array index of |
|
455 | + * 'default' with the value of the default as a string. |
|
456 | + * |
|
457 | + * {@internal Duplicate of same method as contained in the `\PHP_CodeSniffer_File` |
|
458 | + * class. |
|
459 | + * |
|
460 | + * Last synced with PHPCS version: PHPCS 3.3.0-alpha at commit 53a28408d345044c0360c2c1b4a2aaebf4a3b8c9}} |
|
461 | + * |
|
462 | + * @param \PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
|
463 | + * @param int $stackPtr The position in the stack of the |
|
464 | + * function token to acquire the |
|
465 | + * parameters for. |
|
466 | + * |
|
467 | + * @return array|false |
|
468 | + * @throws \PHP_CodeSniffer_Exception If the specified $stackPtr is not of |
|
469 | + * type T_FUNCTION or T_CLOSURE. |
|
470 | + */ |
|
471 | + public static function getMethodParameters(File $phpcsFile, $stackPtr) |
|
472 | + { |
|
473 | + if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
|
474 | + return $phpcsFile->getMethodParameters($stackPtr); |
|
475 | + } |
|
476 | + |
|
477 | + $tokens = $phpcsFile->getTokens(); |
|
478 | + |
|
479 | + // Check for the existence of the token. |
|
480 | + if (isset($tokens[$stackPtr]) === false) { |
|
481 | + return false; |
|
482 | + } |
|
483 | + |
|
484 | + if ($tokens[$stackPtr]['code'] !== \T_FUNCTION |
|
485 | + && $tokens[$stackPtr]['code'] !== \T_CLOSURE |
|
486 | + ) { |
|
487 | + throw new PHPCS_Exception('$stackPtr must be of type T_FUNCTION or T_CLOSURE'); |
|
488 | + } |
|
489 | + |
|
490 | + $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
491 | + $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
492 | + |
|
493 | + $vars = array(); |
|
494 | + $currVar = null; |
|
495 | + $paramStart = ($opener + 1); |
|
496 | + $defaultStart = null; |
|
497 | + $paramCount = 0; |
|
498 | + $passByReference = false; |
|
499 | + $variableLength = false; |
|
500 | + $typeHint = ''; |
|
501 | + $typeHintToken = false; |
|
502 | + $nullableType = false; |
|
503 | + |
|
504 | + for ($i = $paramStart; $i <= $closer; $i++) { |
|
505 | + // Check to see if this token has a parenthesis or bracket opener. If it does |
|
506 | + // it's likely to be an array which might have arguments in it. This |
|
507 | + // could cause problems in our parsing below, so lets just skip to the |
|
508 | + // end of it. |
|
509 | + if (isset($tokens[$i]['parenthesis_opener']) === true) { |
|
510 | + // Don't do this if it's the close parenthesis for the method. |
|
511 | + if ($i !== $tokens[$i]['parenthesis_closer']) { |
|
512 | + $i = ($tokens[$i]['parenthesis_closer'] + 1); |
|
513 | + } |
|
514 | + } |
|
515 | + |
|
516 | + if (isset($tokens[$i]['bracket_opener']) === true) { |
|
517 | + // Don't do this if it's the close parenthesis for the method. |
|
518 | + if ($i !== $tokens[$i]['bracket_closer']) { |
|
519 | + $i = ($tokens[$i]['bracket_closer'] + 1); |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + switch ($tokens[$i]['type']) { |
|
524 | + case 'T_BITWISE_AND': |
|
525 | + if ($defaultStart === null) { |
|
526 | + $passByReference = true; |
|
527 | + } |
|
528 | + break; |
|
529 | + case 'T_VARIABLE': |
|
530 | + $currVar = $i; |
|
531 | + break; |
|
532 | + case 'T_ELLIPSIS': |
|
533 | + $variableLength = true; |
|
534 | + break; |
|
535 | + case 'T_ARRAY_HINT': // Pre-PHPCS 3.3.0. |
|
536 | + case 'T_CALLABLE': |
|
537 | + if ($typeHintToken === false) { |
|
538 | + $typeHintToken = $i; |
|
539 | + } |
|
540 | + |
|
541 | + $typeHint .= $tokens[$i]['content']; |
|
542 | + break; |
|
543 | + case 'T_SELF': |
|
544 | + case 'T_PARENT': |
|
545 | + case 'T_STATIC': |
|
546 | + // Self and parent are valid, static invalid, but was probably intended as type hint. |
|
547 | + if (isset($defaultStart) === false) { |
|
548 | + if ($typeHintToken === false) { |
|
549 | + $typeHintToken = $i; |
|
550 | + } |
|
551 | + |
|
552 | + $typeHint .= $tokens[$i]['content']; |
|
553 | + } |
|
554 | + break; |
|
555 | + case 'T_STRING': |
|
556 | + // This is a string, so it may be a type hint, but it could |
|
557 | + // also be a constant used as a default value. |
|
558 | + $prevComma = false; |
|
559 | + for ($t = $i; $t >= $opener; $t--) { |
|
560 | + if ($tokens[$t]['code'] === \T_COMMA) { |
|
561 | + $prevComma = $t; |
|
562 | + break; |
|
563 | + } |
|
564 | + } |
|
565 | + |
|
566 | + if ($prevComma !== false) { |
|
567 | + $nextEquals = false; |
|
568 | + for ($t = $prevComma; $t < $i; $t++) { |
|
569 | + if ($tokens[$t]['code'] === \T_EQUAL) { |
|
570 | + $nextEquals = $t; |
|
571 | + break; |
|
572 | + } |
|
573 | + } |
|
574 | + |
|
575 | + if ($nextEquals !== false) { |
|
576 | + break; |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + if ($defaultStart === null) { |
|
581 | + if ($typeHintToken === false) { |
|
582 | + $typeHintToken = $i; |
|
583 | + } |
|
584 | + |
|
585 | + $typeHint .= $tokens[$i]['content']; |
|
586 | + } |
|
587 | + break; |
|
588 | + case 'T_NS_SEPARATOR': |
|
589 | + // Part of a type hint or default value. |
|
590 | + if ($defaultStart === null) { |
|
591 | + if ($typeHintToken === false) { |
|
592 | + $typeHintToken = $i; |
|
593 | + } |
|
594 | + |
|
595 | + $typeHint .= $tokens[$i]['content']; |
|
596 | + } |
|
597 | + break; |
|
598 | + case 'T_NULLABLE': |
|
599 | + case 'T_INLINE_THEN': // Pre-PHPCS 2.8.0. |
|
600 | + if ($defaultStart === null) { |
|
601 | + $nullableType = true; |
|
602 | + $typeHint .= $tokens[$i]['content']; |
|
603 | + } |
|
604 | + break; |
|
605 | + case 'T_CLOSE_PARENTHESIS': |
|
606 | + case 'T_COMMA': |
|
607 | + // If it's null, then there must be no parameters for this |
|
608 | + // method. |
|
609 | + if ($currVar === null) { |
|
610 | + break; |
|
611 | + } |
|
612 | + |
|
613 | + $vars[$paramCount] = array(); |
|
614 | + $vars[$paramCount]['token'] = $currVar; |
|
615 | + $vars[$paramCount]['name'] = $tokens[$currVar]['content']; |
|
616 | + $vars[$paramCount]['content'] = trim($phpcsFile->getTokensAsString($paramStart, ($i - $paramStart))); |
|
617 | + |
|
618 | + if ($defaultStart !== null) { |
|
619 | + $vars[$paramCount]['default'] = trim( |
|
620 | + $phpcsFile->getTokensAsString( |
|
621 | + $defaultStart, |
|
622 | + ($i - $defaultStart) |
|
623 | + ) |
|
624 | + ); |
|
625 | + } |
|
626 | + |
|
627 | + $vars[$paramCount]['pass_by_reference'] = $passByReference; |
|
628 | + $vars[$paramCount]['variable_length'] = $variableLength; |
|
629 | + $vars[$paramCount]['type_hint'] = $typeHint; |
|
630 | + $vars[$paramCount]['type_hint_token'] = $typeHintToken; |
|
631 | + $vars[$paramCount]['nullable_type'] = $nullableType; |
|
632 | + |
|
633 | + // Reset the vars, as we are about to process the next parameter. |
|
634 | + $defaultStart = null; |
|
635 | + $paramStart = ($i + 1); |
|
636 | + $passByReference = false; |
|
637 | + $variableLength = false; |
|
638 | + $typeHint = ''; |
|
639 | + $typeHintToken = false; |
|
640 | + $nullableType = false; |
|
641 | + |
|
642 | + $paramCount++; |
|
643 | + break; |
|
644 | + case 'T_EQUAL': |
|
645 | + $defaultStart = ($i + 1); |
|
646 | + break; |
|
647 | + }//end switch |
|
648 | + }//end for |
|
649 | + |
|
650 | + return $vars; |
|
651 | + } |
|
652 | 652 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public static function getVersion() |
39 | 39 | { |
40 | - if (\defined('\PHP_CodeSniffer\Config::VERSION')) { |
|
40 | + if ( \defined( '\PHP_CodeSniffer\Config::VERSION' ) ) { |
|
41 | 41 | // PHPCS 3.x. |
42 | 42 | return \PHP_CodeSniffer\Config::VERSION; |
43 | 43 | } else { |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return void |
62 | 62 | */ |
63 | - public static function setConfigData($key, $value, $temp = false) |
|
63 | + public static function setConfigData( $key, $value, $temp = false ) |
|
64 | 64 | { |
65 | - if (method_exists('\PHP_CodeSniffer\Config', 'setConfigData')) { |
|
65 | + if ( method_exists( '\PHP_CodeSniffer\Config', 'setConfigData' ) ) { |
|
66 | 66 | // PHPCS 3.x. |
67 | - \PHP_CodeSniffer\Config::setConfigData($key, $value, $temp); |
|
67 | + \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); |
|
68 | 68 | } else { |
69 | 69 | // PHPCS 2.x. |
70 | - \PHP_CodeSniffer::setConfigData($key, $value, $temp); |
|
70 | + \PHP_CodeSniffer::setConfigData( $key, $value, $temp ); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return string|null |
81 | 81 | */ |
82 | - public static function getConfigData($key) |
|
82 | + public static function getConfigData( $key ) |
|
83 | 83 | { |
84 | - if (method_exists('\PHP_CodeSniffer\Config', 'getConfigData')) { |
|
84 | + if ( method_exists( '\PHP_CodeSniffer\Config', 'getConfigData' ) ) { |
|
85 | 85 | // PHPCS 3.x. |
86 | - return \PHP_CodeSniffer\Config::getConfigData($key); |
|
86 | + return \PHP_CodeSniffer\Config::getConfigData( $key ); |
|
87 | 87 | } else { |
88 | 88 | // PHPCS 2.x. |
89 | - return \PHP_CodeSniffer::getConfigData($key); |
|
89 | + return \PHP_CodeSniffer::getConfigData( $key ); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -102,19 +102,19 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @return string|null |
104 | 104 | */ |
105 | - public static function getCommandLineData(File $phpcsFile, $key) |
|
105 | + public static function getCommandLineData( File $phpcsFile, $key ) |
|
106 | 106 | { |
107 | - if (class_exists('\PHP_CodeSniffer\Config')) { |
|
107 | + if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { |
|
108 | 108 | // PHPCS 3.x. |
109 | 109 | $config = $phpcsFile->config; |
110 | - if (isset($config->{$key})) { |
|
110 | + if ( isset( $config->{$key}) ) { |
|
111 | 111 | return $config->{$key}; |
112 | 112 | } |
113 | 113 | } else { |
114 | 114 | // PHPCS 2.x. |
115 | 115 | $config = $phpcsFile->phpcs->cli->getCommandLineValues(); |
116 | - if (isset($config[$key])) { |
|
117 | - return $config[$key]; |
|
116 | + if ( isset( $config[ $key ] ) ) { |
|
117 | + return $config[ $key ]; |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -140,59 +140,59 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return int |
142 | 142 | */ |
143 | - public static function findStartOfStatement(File $phpcsFile, $start, $ignore = null) |
|
143 | + public static function findStartOfStatement( File $phpcsFile, $start, $ignore = null ) |
|
144 | 144 | { |
145 | - if (version_compare(self::getVersion(), '2.7.1', '>=') === true) { |
|
146 | - return $phpcsFile->findStartOfStatement($start, $ignore); |
|
145 | + if ( version_compare( self::getVersion(), '2.7.1', '>=' ) === true ) { |
|
146 | + return $phpcsFile->findStartOfStatement( $start, $ignore ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | $tokens = $phpcsFile->getTokens(); |
150 | 150 | $endTokens = Tokens::$blockOpeners; |
151 | 151 | |
152 | - $endTokens[\T_COLON] = true; |
|
153 | - $endTokens[\T_COMMA] = true; |
|
154 | - $endTokens[\T_DOUBLE_ARROW] = true; |
|
155 | - $endTokens[\T_SEMICOLON] = true; |
|
156 | - $endTokens[\T_OPEN_TAG] = true; |
|
157 | - $endTokens[\T_CLOSE_TAG] = true; |
|
158 | - $endTokens[\T_OPEN_SHORT_ARRAY] = true; |
|
159 | - |
|
160 | - if ($ignore !== null) { |
|
161 | - $ignore = (array) $ignore; |
|
162 | - foreach ($ignore as $code) { |
|
163 | - if (isset($endTokens[$code]) === true) { |
|
164 | - unset($endTokens[$code]); |
|
152 | + $endTokens[ \T_COLON ] = true; |
|
153 | + $endTokens[ \T_COMMA ] = true; |
|
154 | + $endTokens[ \T_DOUBLE_ARROW ] = true; |
|
155 | + $endTokens[ \T_SEMICOLON ] = true; |
|
156 | + $endTokens[ \T_OPEN_TAG ] = true; |
|
157 | + $endTokens[ \T_CLOSE_TAG ] = true; |
|
158 | + $endTokens[ \T_OPEN_SHORT_ARRAY ] = true; |
|
159 | + |
|
160 | + if ( $ignore !== null ) { |
|
161 | + $ignore = (array)$ignore; |
|
162 | + foreach ( $ignore as $code ) { |
|
163 | + if ( isset( $endTokens[ $code ] ) === true ) { |
|
164 | + unset( $endTokens[ $code ] ); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | 169 | $lastNotEmpty = $start; |
170 | 170 | |
171 | - for ($i = $start; $i >= 0; $i--) { |
|
172 | - if (isset($endTokens[$tokens[$i]['code']]) === true) { |
|
171 | + for ( $i = $start; $i >= 0; $i-- ) { |
|
172 | + if ( isset( $endTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
173 | 173 | // Found the end of the previous statement. |
174 | 174 | return $lastNotEmpty; |
175 | 175 | } |
176 | 176 | |
177 | - if (isset($tokens[$i]['scope_opener']) === true |
|
178 | - && $i === $tokens[$i]['scope_closer'] |
|
177 | + if ( isset( $tokens[ $i ][ 'scope_opener' ] ) === true |
|
178 | + && $i === $tokens[ $i ][ 'scope_closer' ] |
|
179 | 179 | ) { |
180 | 180 | // Found the end of the previous scope block. |
181 | 181 | return $lastNotEmpty; |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Skip nested statements. |
185 | - if (isset($tokens[$i]['bracket_opener']) === true |
|
186 | - && $i === $tokens[$i]['bracket_closer'] |
|
185 | + if ( isset( $tokens[ $i ][ 'bracket_opener' ] ) === true |
|
186 | + && $i === $tokens[ $i ][ 'bracket_closer' ] |
|
187 | 187 | ) { |
188 | - $i = $tokens[$i]['bracket_opener']; |
|
189 | - } elseif (isset($tokens[$i]['parenthesis_opener']) === true |
|
190 | - && $i === $tokens[$i]['parenthesis_closer'] |
|
188 | + $i = $tokens[ $i ][ 'bracket_opener' ]; |
|
189 | + } elseif ( isset( $tokens[ $i ][ 'parenthesis_opener' ] ) === true |
|
190 | + && $i === $tokens[ $i ][ 'parenthesis_closer' ] |
|
191 | 191 | ) { |
192 | - $i = $tokens[$i]['parenthesis_opener']; |
|
192 | + $i = $tokens[ $i ][ 'parenthesis_opener' ]; |
|
193 | 193 | } |
194 | 194 | |
195 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { |
|
195 | + if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === false ) { |
|
196 | 196 | $lastNotEmpty = $i; |
197 | 197 | } |
198 | 198 | }//end for |
@@ -219,10 +219,10 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return int |
221 | 221 | */ |
222 | - public static function findEndOfStatement(File $phpcsFile, $start, $ignore = null) |
|
222 | + public static function findEndOfStatement( File $phpcsFile, $start, $ignore = null ) |
|
223 | 223 | { |
224 | - if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
|
225 | - return $phpcsFile->findEndOfStatement($start, $ignore); |
|
224 | + if ( version_compare( self::getVersion(), '3.3.0', '>=' ) === true ) { |
|
225 | + return $phpcsFile->findEndOfStatement( $start, $ignore ); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | $tokens = $phpcsFile->getTokens(); |
@@ -239,26 +239,26 @@ discard block |
||
239 | 239 | \T_CLOSE_TAG => true, |
240 | 240 | ); |
241 | 241 | |
242 | - if ($ignore !== null) { |
|
243 | - $ignore = (array) $ignore; |
|
244 | - foreach ($ignore as $code) { |
|
245 | - if (isset($endTokens[$code]) === true) { |
|
246 | - unset($endTokens[$code]); |
|
242 | + if ( $ignore !== null ) { |
|
243 | + $ignore = (array)$ignore; |
|
244 | + foreach ( $ignore as $code ) { |
|
245 | + if ( isset( $endTokens[ $code ] ) === true ) { |
|
246 | + unset( $endTokens[ $code ] ); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | 251 | $lastNotEmpty = $start; |
252 | 252 | |
253 | - for ($i = $start; $i < $phpcsFile->numTokens; $i++) { |
|
254 | - if ($i !== $start && isset($endTokens[$tokens[$i]['code']]) === true) { |
|
253 | + for ( $i = $start; $i < $phpcsFile->numTokens; $i++ ) { |
|
254 | + if ( $i !== $start && isset( $endTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
255 | 255 | // Found the end of the statement. |
256 | - if ($tokens[$i]['code'] === \T_CLOSE_PARENTHESIS |
|
257 | - || $tokens[$i]['code'] === \T_CLOSE_SQUARE_BRACKET |
|
258 | - || $tokens[$i]['code'] === \T_CLOSE_CURLY_BRACKET |
|
259 | - || $tokens[$i]['code'] === \T_CLOSE_SHORT_ARRAY |
|
260 | - || $tokens[$i]['code'] === \T_OPEN_TAG |
|
261 | - || $tokens[$i]['code'] === \T_CLOSE_TAG |
|
256 | + if ( $tokens[ $i ][ 'code' ] === \T_CLOSE_PARENTHESIS |
|
257 | + || $tokens[ $i ][ 'code' ] === \T_CLOSE_SQUARE_BRACKET |
|
258 | + || $tokens[ $i ][ 'code' ] === \T_CLOSE_CURLY_BRACKET |
|
259 | + || $tokens[ $i ][ 'code' ] === \T_CLOSE_SHORT_ARRAY |
|
260 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_TAG |
|
261 | + || $tokens[ $i ][ 'code' ] === \T_CLOSE_TAG |
|
262 | 262 | ) { |
263 | 263 | return $lastNotEmpty; |
264 | 264 | } |
@@ -267,31 +267,31 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | // Skip nested statements. |
270 | - if (isset($tokens[$i]['scope_closer']) === true |
|
271 | - && ($i === $tokens[$i]['scope_opener'] |
|
272 | - || $i === $tokens[$i]['scope_condition']) |
|
270 | + if ( isset( $tokens[ $i ][ 'scope_closer' ] ) === true |
|
271 | + && ( $i === $tokens[ $i ][ 'scope_opener' ] |
|
272 | + || $i === $tokens[ $i ][ 'scope_condition' ] ) |
|
273 | 273 | ) { |
274 | - if ($i === $start && isset(Tokens::$scopeOpeners[$tokens[$i]['code']]) === true) { |
|
275 | - return $tokens[$i]['scope_closer']; |
|
274 | + if ( $i === $start && isset( Tokens::$scopeOpeners[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
275 | + return $tokens[ $i ][ 'scope_closer' ]; |
|
276 | 276 | } |
277 | 277 | |
278 | - $i = $tokens[$i]['scope_closer']; |
|
279 | - } elseif (isset($tokens[$i]['bracket_closer']) === true |
|
280 | - && $i === $tokens[$i]['bracket_opener'] |
|
278 | + $i = $tokens[ $i ][ 'scope_closer' ]; |
|
279 | + } elseif ( isset( $tokens[ $i ][ 'bracket_closer' ] ) === true |
|
280 | + && $i === $tokens[ $i ][ 'bracket_opener' ] |
|
281 | 281 | ) { |
282 | - $i = $tokens[$i]['bracket_closer']; |
|
283 | - } elseif (isset($tokens[$i]['parenthesis_closer']) === true |
|
284 | - && $i === $tokens[$i]['parenthesis_opener'] |
|
282 | + $i = $tokens[ $i ][ 'bracket_closer' ]; |
|
283 | + } elseif ( isset( $tokens[ $i ][ 'parenthesis_closer' ] ) === true |
|
284 | + && $i === $tokens[ $i ][ 'parenthesis_opener' ] |
|
285 | 285 | ) { |
286 | - $i = $tokens[$i]['parenthesis_closer']; |
|
286 | + $i = $tokens[ $i ][ 'parenthesis_closer' ]; |
|
287 | 287 | } |
288 | 288 | |
289 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { |
|
289 | + if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === false ) { |
|
290 | 290 | $lastNotEmpty = $i; |
291 | 291 | } |
292 | 292 | }//end for |
293 | 293 | |
294 | - return ($phpcsFile->numTokens - 1); |
|
294 | + return ( $phpcsFile->numTokens - 1 ); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | |
@@ -317,33 +317,33 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @return string|false |
319 | 319 | */ |
320 | - public static function findExtendedClassName(File $phpcsFile, $stackPtr) |
|
320 | + public static function findExtendedClassName( File $phpcsFile, $stackPtr ) |
|
321 | 321 | { |
322 | - if (version_compare(self::getVersion(), '3.1.0', '>=') === true) { |
|
323 | - return $phpcsFile->findExtendedClassName($stackPtr); |
|
322 | + if ( version_compare( self::getVersion(), '3.1.0', '>=' ) === true ) { |
|
323 | + return $phpcsFile->findExtendedClassName( $stackPtr ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | $tokens = $phpcsFile->getTokens(); |
327 | 327 | |
328 | 328 | // Check for the existence of the token. |
329 | - if (isset($tokens[$stackPtr]) === false) { |
|
329 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
330 | 330 | return false; |
331 | 331 | } |
332 | 332 | |
333 | - if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
334 | - && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
335 | - && $tokens[$stackPtr]['type'] !== 'T_INTERFACE' |
|
333 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_CLASS |
|
334 | + && $tokens[ $stackPtr ][ 'type' ] !== 'T_ANON_CLASS' |
|
335 | + && $tokens[ $stackPtr ][ 'type' ] !== 'T_INTERFACE' |
|
336 | 336 | ) { |
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
340 | + if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) { |
|
341 | 341 | return false; |
342 | 342 | } |
343 | 343 | |
344 | - $classCloserIndex = $tokens[$stackPtr]['scope_closer']; |
|
345 | - $extendsIndex = $phpcsFile->findNext(\T_EXTENDS, $stackPtr, $classCloserIndex); |
|
346 | - if ($extendsIndex === false) { |
|
344 | + $classCloserIndex = $tokens[ $stackPtr ][ 'scope_closer' ]; |
|
345 | + $extendsIndex = $phpcsFile->findNext( \T_EXTENDS, $stackPtr, $classCloserIndex ); |
|
346 | + if ( $extendsIndex === false ) { |
|
347 | 347 | return false; |
348 | 348 | } |
349 | 349 | |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | \T_WHITESPACE, |
354 | 354 | ); |
355 | 355 | |
356 | - $end = $phpcsFile->findNext($find, ($extendsIndex + 1), $classCloserIndex, true); |
|
357 | - $name = $phpcsFile->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1)); |
|
358 | - $name = trim($name); |
|
356 | + $end = $phpcsFile->findNext( $find, ( $extendsIndex + 1 ), $classCloserIndex, true ); |
|
357 | + $name = $phpcsFile->getTokensAsString( ( $extendsIndex + 1 ), ( $end - $extendsIndex - 1 ) ); |
|
358 | + $name = trim( $name ); |
|
359 | 359 | |
360 | - if ($name === '') { |
|
360 | + if ( $name === '' ) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | |
@@ -382,32 +382,32 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @return array|false |
384 | 384 | */ |
385 | - public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) |
|
385 | + public static function findImplementedInterfaceNames( File $phpcsFile, $stackPtr ) |
|
386 | 386 | { |
387 | - if (version_compare(self::getVersion(), '2.7.1', '>') === true) { |
|
388 | - return $phpcsFile->findImplementedInterfaceNames($stackPtr); |
|
387 | + if ( version_compare( self::getVersion(), '2.7.1', '>' ) === true ) { |
|
388 | + return $phpcsFile->findImplementedInterfaceNames( $stackPtr ); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | $tokens = $phpcsFile->getTokens(); |
392 | 392 | |
393 | 393 | // Check for the existence of the token. |
394 | - if (isset($tokens[$stackPtr]) === false) { |
|
394 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
395 | 395 | return false; |
396 | 396 | } |
397 | 397 | |
398 | - if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
399 | - && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
398 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_CLASS |
|
399 | + && $tokens[ $stackPtr ][ 'type' ] !== 'T_ANON_CLASS' |
|
400 | 400 | ) { |
401 | 401 | return false; |
402 | 402 | } |
403 | 403 | |
404 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
404 | + if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) { |
|
405 | 405 | return false; |
406 | 406 | } |
407 | 407 | |
408 | - $classOpenerIndex = $tokens[$stackPtr]['scope_opener']; |
|
409 | - $implementsIndex = $phpcsFile->findNext(\T_IMPLEMENTS, $stackPtr, $classOpenerIndex); |
|
410 | - if ($implementsIndex === false) { |
|
408 | + $classOpenerIndex = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
409 | + $implementsIndex = $phpcsFile->findNext( \T_IMPLEMENTS, $stackPtr, $classOpenerIndex ); |
|
410 | + if ( $implementsIndex === false ) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | |
@@ -418,15 +418,15 @@ discard block |
||
418 | 418 | \T_COMMA, |
419 | 419 | ); |
420 | 420 | |
421 | - $end = $phpcsFile->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true); |
|
422 | - $name = $phpcsFile->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1)); |
|
423 | - $name = trim($name); |
|
421 | + $end = $phpcsFile->findNext( $find, ( $implementsIndex + 1 ), ( $classOpenerIndex + 1 ), true ); |
|
422 | + $name = $phpcsFile->getTokensAsString( ( $implementsIndex + 1 ), ( $end - $implementsIndex - 1 ) ); |
|
423 | + $name = trim( $name ); |
|
424 | 424 | |
425 | - if ($name === '') { |
|
425 | + if ( $name === '' ) { |
|
426 | 426 | return false; |
427 | 427 | } else { |
428 | - $names = explode(',', $name); |
|
429 | - $names = array_map('trim', $names); |
|
428 | + $names = explode( ',', $name ); |
|
429 | + $names = array_map( 'trim', $names ); |
|
430 | 430 | return $names; |
431 | 431 | } |
432 | 432 | } |
@@ -468,31 +468,31 @@ discard block |
||
468 | 468 | * @throws \PHP_CodeSniffer_Exception If the specified $stackPtr is not of |
469 | 469 | * type T_FUNCTION or T_CLOSURE. |
470 | 470 | */ |
471 | - public static function getMethodParameters(File $phpcsFile, $stackPtr) |
|
471 | + public static function getMethodParameters( File $phpcsFile, $stackPtr ) |
|
472 | 472 | { |
473 | - if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
|
474 | - return $phpcsFile->getMethodParameters($stackPtr); |
|
473 | + if ( version_compare( self::getVersion(), '3.3.0', '>=' ) === true ) { |
|
474 | + return $phpcsFile->getMethodParameters( $stackPtr ); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | $tokens = $phpcsFile->getTokens(); |
478 | 478 | |
479 | 479 | // Check for the existence of the token. |
480 | - if (isset($tokens[$stackPtr]) === false) { |
|
480 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
481 | 481 | return false; |
482 | 482 | } |
483 | 483 | |
484 | - if ($tokens[$stackPtr]['code'] !== \T_FUNCTION |
|
485 | - && $tokens[$stackPtr]['code'] !== \T_CLOSURE |
|
484 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_FUNCTION |
|
485 | + && $tokens[ $stackPtr ][ 'code' ] !== \T_CLOSURE |
|
486 | 486 | ) { |
487 | - throw new PHPCS_Exception('$stackPtr must be of type T_FUNCTION or T_CLOSURE'); |
|
487 | + throw new PHPCS_Exception( '$stackPtr must be of type T_FUNCTION or T_CLOSURE' ); |
|
488 | 488 | } |
489 | 489 | |
490 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
491 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
490 | + $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
491 | + $closer = $tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
492 | 492 | |
493 | 493 | $vars = array(); |
494 | 494 | $currVar = null; |
495 | - $paramStart = ($opener + 1); |
|
495 | + $paramStart = ( $opener + 1 ); |
|
496 | 496 | $defaultStart = null; |
497 | 497 | $paramCount = 0; |
498 | 498 | $passByReference = false; |
@@ -501,28 +501,28 @@ discard block |
||
501 | 501 | $typeHintToken = false; |
502 | 502 | $nullableType = false; |
503 | 503 | |
504 | - for ($i = $paramStart; $i <= $closer; $i++) { |
|
504 | + for ( $i = $paramStart; $i <= $closer; $i++ ) { |
|
505 | 505 | // Check to see if this token has a parenthesis or bracket opener. If it does |
506 | 506 | // it's likely to be an array which might have arguments in it. This |
507 | 507 | // could cause problems in our parsing below, so lets just skip to the |
508 | 508 | // end of it. |
509 | - if (isset($tokens[$i]['parenthesis_opener']) === true) { |
|
509 | + if ( isset( $tokens[ $i ][ 'parenthesis_opener' ] ) === true ) { |
|
510 | 510 | // Don't do this if it's the close parenthesis for the method. |
511 | - if ($i !== $tokens[$i]['parenthesis_closer']) { |
|
512 | - $i = ($tokens[$i]['parenthesis_closer'] + 1); |
|
511 | + if ( $i !== $tokens[ $i ][ 'parenthesis_closer' ] ) { |
|
512 | + $i = ( $tokens[ $i ][ 'parenthesis_closer' ] + 1 ); |
|
513 | 513 | } |
514 | 514 | } |
515 | 515 | |
516 | - if (isset($tokens[$i]['bracket_opener']) === true) { |
|
516 | + if ( isset( $tokens[ $i ][ 'bracket_opener' ] ) === true ) { |
|
517 | 517 | // Don't do this if it's the close parenthesis for the method. |
518 | - if ($i !== $tokens[$i]['bracket_closer']) { |
|
519 | - $i = ($tokens[$i]['bracket_closer'] + 1); |
|
518 | + if ( $i !== $tokens[ $i ][ 'bracket_closer' ] ) { |
|
519 | + $i = ( $tokens[ $i ][ 'bracket_closer' ] + 1 ); |
|
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | - switch ($tokens[$i]['type']) { |
|
523 | + switch ( $tokens[ $i ][ 'type' ] ) { |
|
524 | 524 | case 'T_BITWISE_AND': |
525 | - if ($defaultStart === null) { |
|
525 | + if ( $defaultStart === null ) { |
|
526 | 526 | $passByReference = true; |
527 | 527 | } |
528 | 528 | break; |
@@ -534,105 +534,105 @@ discard block |
||
534 | 534 | break; |
535 | 535 | case 'T_ARRAY_HINT': // Pre-PHPCS 3.3.0. |
536 | 536 | case 'T_CALLABLE': |
537 | - if ($typeHintToken === false) { |
|
537 | + if ( $typeHintToken === false ) { |
|
538 | 538 | $typeHintToken = $i; |
539 | 539 | } |
540 | 540 | |
541 | - $typeHint .= $tokens[$i]['content']; |
|
541 | + $typeHint .= $tokens[ $i ][ 'content' ]; |
|
542 | 542 | break; |
543 | 543 | case 'T_SELF': |
544 | 544 | case 'T_PARENT': |
545 | 545 | case 'T_STATIC': |
546 | 546 | // Self and parent are valid, static invalid, but was probably intended as type hint. |
547 | - if (isset($defaultStart) === false) { |
|
548 | - if ($typeHintToken === false) { |
|
547 | + if ( isset( $defaultStart ) === false ) { |
|
548 | + if ( $typeHintToken === false ) { |
|
549 | 549 | $typeHintToken = $i; |
550 | 550 | } |
551 | 551 | |
552 | - $typeHint .= $tokens[$i]['content']; |
|
552 | + $typeHint .= $tokens[ $i ][ 'content' ]; |
|
553 | 553 | } |
554 | 554 | break; |
555 | 555 | case 'T_STRING': |
556 | 556 | // This is a string, so it may be a type hint, but it could |
557 | 557 | // also be a constant used as a default value. |
558 | 558 | $prevComma = false; |
559 | - for ($t = $i; $t >= $opener; $t--) { |
|
560 | - if ($tokens[$t]['code'] === \T_COMMA) { |
|
559 | + for ( $t = $i; $t >= $opener; $t-- ) { |
|
560 | + if ( $tokens[ $t ][ 'code' ] === \T_COMMA ) { |
|
561 | 561 | $prevComma = $t; |
562 | 562 | break; |
563 | 563 | } |
564 | 564 | } |
565 | 565 | |
566 | - if ($prevComma !== false) { |
|
566 | + if ( $prevComma !== false ) { |
|
567 | 567 | $nextEquals = false; |
568 | - for ($t = $prevComma; $t < $i; $t++) { |
|
569 | - if ($tokens[$t]['code'] === \T_EQUAL) { |
|
568 | + for ( $t = $prevComma; $t < $i; $t++ ) { |
|
569 | + if ( $tokens[ $t ][ 'code' ] === \T_EQUAL ) { |
|
570 | 570 | $nextEquals = $t; |
571 | 571 | break; |
572 | 572 | } |
573 | 573 | } |
574 | 574 | |
575 | - if ($nextEquals !== false) { |
|
575 | + if ( $nextEquals !== false ) { |
|
576 | 576 | break; |
577 | 577 | } |
578 | 578 | } |
579 | 579 | |
580 | - if ($defaultStart === null) { |
|
581 | - if ($typeHintToken === false) { |
|
580 | + if ( $defaultStart === null ) { |
|
581 | + if ( $typeHintToken === false ) { |
|
582 | 582 | $typeHintToken = $i; |
583 | 583 | } |
584 | 584 | |
585 | - $typeHint .= $tokens[$i]['content']; |
|
585 | + $typeHint .= $tokens[ $i ][ 'content' ]; |
|
586 | 586 | } |
587 | 587 | break; |
588 | 588 | case 'T_NS_SEPARATOR': |
589 | 589 | // Part of a type hint or default value. |
590 | - if ($defaultStart === null) { |
|
591 | - if ($typeHintToken === false) { |
|
590 | + if ( $defaultStart === null ) { |
|
591 | + if ( $typeHintToken === false ) { |
|
592 | 592 | $typeHintToken = $i; |
593 | 593 | } |
594 | 594 | |
595 | - $typeHint .= $tokens[$i]['content']; |
|
595 | + $typeHint .= $tokens[ $i ][ 'content' ]; |
|
596 | 596 | } |
597 | 597 | break; |
598 | 598 | case 'T_NULLABLE': |
599 | 599 | case 'T_INLINE_THEN': // Pre-PHPCS 2.8.0. |
600 | - if ($defaultStart === null) { |
|
600 | + if ( $defaultStart === null ) { |
|
601 | 601 | $nullableType = true; |
602 | - $typeHint .= $tokens[$i]['content']; |
|
602 | + $typeHint .= $tokens[ $i ][ 'content' ]; |
|
603 | 603 | } |
604 | 604 | break; |
605 | 605 | case 'T_CLOSE_PARENTHESIS': |
606 | 606 | case 'T_COMMA': |
607 | 607 | // If it's null, then there must be no parameters for this |
608 | 608 | // method. |
609 | - if ($currVar === null) { |
|
609 | + if ( $currVar === null ) { |
|
610 | 610 | break; |
611 | 611 | } |
612 | 612 | |
613 | - $vars[$paramCount] = array(); |
|
614 | - $vars[$paramCount]['token'] = $currVar; |
|
615 | - $vars[$paramCount]['name'] = $tokens[$currVar]['content']; |
|
616 | - $vars[$paramCount]['content'] = trim($phpcsFile->getTokensAsString($paramStart, ($i - $paramStart))); |
|
613 | + $vars[ $paramCount ] = array(); |
|
614 | + $vars[ $paramCount ][ 'token' ] = $currVar; |
|
615 | + $vars[ $paramCount ][ 'name' ] = $tokens[ $currVar ][ 'content' ]; |
|
616 | + $vars[ $paramCount ][ 'content' ] = trim( $phpcsFile->getTokensAsString( $paramStart, ( $i - $paramStart ) ) ); |
|
617 | 617 | |
618 | - if ($defaultStart !== null) { |
|
619 | - $vars[$paramCount]['default'] = trim( |
|
618 | + if ( $defaultStart !== null ) { |
|
619 | + $vars[ $paramCount ][ 'default' ] = trim( |
|
620 | 620 | $phpcsFile->getTokensAsString( |
621 | 621 | $defaultStart, |
622 | - ($i - $defaultStart) |
|
622 | + ( $i - $defaultStart ) |
|
623 | 623 | ) |
624 | 624 | ); |
625 | 625 | } |
626 | 626 | |
627 | - $vars[$paramCount]['pass_by_reference'] = $passByReference; |
|
628 | - $vars[$paramCount]['variable_length'] = $variableLength; |
|
629 | - $vars[$paramCount]['type_hint'] = $typeHint; |
|
630 | - $vars[$paramCount]['type_hint_token'] = $typeHintToken; |
|
631 | - $vars[$paramCount]['nullable_type'] = $nullableType; |
|
627 | + $vars[ $paramCount ][ 'pass_by_reference' ] = $passByReference; |
|
628 | + $vars[ $paramCount ][ 'variable_length' ] = $variableLength; |
|
629 | + $vars[ $paramCount ][ 'type_hint' ] = $typeHint; |
|
630 | + $vars[ $paramCount ][ 'type_hint_token' ] = $typeHintToken; |
|
631 | + $vars[ $paramCount ][ 'nullable_type' ] = $nullableType; |
|
632 | 632 | |
633 | 633 | // Reset the vars, as we are about to process the next parameter. |
634 | 634 | $defaultStart = null; |
635 | - $paramStart = ($i + 1); |
|
635 | + $paramStart = ( $i + 1 ); |
|
636 | 636 | $passByReference = false; |
637 | 637 | $variableLength = false; |
638 | 638 | $typeHint = ''; |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | $paramCount++; |
643 | 643 | break; |
644 | 644 | case 'T_EQUAL': |
645 | - $defaultStart = ($i + 1); |
|
645 | + $defaultStart = ( $i + 1 ); |
|
646 | 646 | break; |
647 | 647 | }//end switch |
648 | 648 | }//end for |
@@ -27,16 +27,14 @@ discard block |
||
27 | 27 | * @package PHPCompatibility |
28 | 28 | * @author Juliette Reinders Folmer <[email protected]> |
29 | 29 | */ |
30 | -class PHPCSHelper |
|
31 | -{ |
|
30 | +class PHPCSHelper { |
|
32 | 31 | |
33 | 32 | /** |
34 | 33 | * Get the PHPCS version number. |
35 | 34 | * |
36 | 35 | * @return string |
37 | 36 | */ |
38 | - public static function getVersion() |
|
39 | - { |
|
37 | + public static function getVersion() { |
|
40 | 38 | if (\defined('\PHP_CodeSniffer\Config::VERSION')) { |
41 | 39 | // PHPCS 3.x. |
42 | 40 | return \PHP_CodeSniffer\Config::VERSION; |
@@ -60,8 +58,7 @@ discard block |
||
60 | 58 | * |
61 | 59 | * @return void |
62 | 60 | */ |
63 | - public static function setConfigData($key, $value, $temp = false) |
|
64 | - { |
|
61 | + public static function setConfigData($key, $value, $temp = false) { |
|
65 | 62 | if (method_exists('\PHP_CodeSniffer\Config', 'setConfigData')) { |
66 | 63 | // PHPCS 3.x. |
67 | 64 | \PHP_CodeSniffer\Config::setConfigData($key, $value, $temp); |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | * |
80 | 77 | * @return string|null |
81 | 78 | */ |
82 | - public static function getConfigData($key) |
|
83 | - { |
|
79 | + public static function getConfigData($key) { |
|
84 | 80 | if (method_exists('\PHP_CodeSniffer\Config', 'getConfigData')) { |
85 | 81 | // PHPCS 3.x. |
86 | 82 | return \PHP_CodeSniffer\Config::getConfigData($key); |
@@ -102,8 +98,7 @@ discard block |
||
102 | 98 | * |
103 | 99 | * @return string|null |
104 | 100 | */ |
105 | - public static function getCommandLineData(File $phpcsFile, $key) |
|
106 | - { |
|
101 | + public static function getCommandLineData(File $phpcsFile, $key) { |
|
107 | 102 | if (class_exists('\PHP_CodeSniffer\Config')) { |
108 | 103 | // PHPCS 3.x. |
109 | 104 | $config = $phpcsFile->config; |
@@ -140,8 +135,7 @@ discard block |
||
140 | 135 | * |
141 | 136 | * @return int |
142 | 137 | */ |
143 | - public static function findStartOfStatement(File $phpcsFile, $start, $ignore = null) |
|
144 | - { |
|
138 | + public static function findStartOfStatement(File $phpcsFile, $start, $ignore = null) { |
|
145 | 139 | if (version_compare(self::getVersion(), '2.7.1', '>=') === true) { |
146 | 140 | return $phpcsFile->findStartOfStatement($start, $ignore); |
147 | 141 | } |
@@ -219,8 +213,7 @@ discard block |
||
219 | 213 | * |
220 | 214 | * @return int |
221 | 215 | */ |
222 | - public static function findEndOfStatement(File $phpcsFile, $start, $ignore = null) |
|
223 | - { |
|
216 | + public static function findEndOfStatement(File $phpcsFile, $start, $ignore = null) { |
|
224 | 217 | if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
225 | 218 | return $phpcsFile->findEndOfStatement($start, $ignore); |
226 | 219 | } |
@@ -317,8 +310,7 @@ discard block |
||
317 | 310 | * |
318 | 311 | * @return string|false |
319 | 312 | */ |
320 | - public static function findExtendedClassName(File $phpcsFile, $stackPtr) |
|
321 | - { |
|
313 | + public static function findExtendedClassName(File $phpcsFile, $stackPtr) { |
|
322 | 314 | if (version_compare(self::getVersion(), '3.1.0', '>=') === true) { |
323 | 315 | return $phpcsFile->findExtendedClassName($stackPtr); |
324 | 316 | } |
@@ -382,8 +374,7 @@ discard block |
||
382 | 374 | * |
383 | 375 | * @return array|false |
384 | 376 | */ |
385 | - public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) |
|
386 | - { |
|
377 | + public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) { |
|
387 | 378 | if (version_compare(self::getVersion(), '2.7.1', '>') === true) { |
388 | 379 | return $phpcsFile->findImplementedInterfaceNames($stackPtr); |
389 | 380 | } |
@@ -468,8 +459,7 @@ discard block |
||
468 | 459 | * @throws \PHP_CodeSniffer_Exception If the specified $stackPtr is not of |
469 | 460 | * type T_FUNCTION or T_CLOSURE. |
470 | 461 | */ |
471 | - public static function getMethodParameters(File $phpcsFile, $stackPtr) |
|
472 | - { |
|
462 | + public static function getMethodParameters(File $phpcsFile, $stackPtr) { |
|
473 | 463 | if (version_compare(self::getVersion(), '3.3.0', '>=') === true) { |
474 | 464 | return $phpcsFile->getMethodParameters($stackPtr); |
475 | 465 | } |
@@ -24,44 +24,44 @@ |
||
24 | 24 | * manner.}} |
25 | 25 | */ |
26 | 26 | if (defined('PHPCOMPATIBILITY_PHPCS_ALIASES_SET') === false) { |
27 | - if (interface_exists('\PHP_CodeSniffer_Sniff') === false) { |
|
28 | - class_alias('PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff'); |
|
29 | - } |
|
30 | - if (class_exists('\PHP_CodeSniffer_File') === false) { |
|
31 | - class_alias('PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File'); |
|
32 | - } |
|
33 | - if (class_exists('\PHP_CodeSniffer_Tokens') === false) { |
|
34 | - class_alias('PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens'); |
|
35 | - } |
|
36 | - if (class_exists('\PHP_CodeSniffer_Exception') === false) { |
|
37 | - class_alias('PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception'); |
|
38 | - } |
|
39 | - if (class_exists('\PHP_CodeSniffer_Standards_AbstractScopeSniff') === false) { |
|
40 | - class_alias('PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff'); |
|
41 | - } |
|
42 | - if (class_exists('\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff') === false) { |
|
43 | - class_alias('PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff', '\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff'); |
|
44 | - } |
|
27 | + if (interface_exists('\PHP_CodeSniffer_Sniff') === false) { |
|
28 | + class_alias('PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff'); |
|
29 | + } |
|
30 | + if (class_exists('\PHP_CodeSniffer_File') === false) { |
|
31 | + class_alias('PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File'); |
|
32 | + } |
|
33 | + if (class_exists('\PHP_CodeSniffer_Tokens') === false) { |
|
34 | + class_alias('PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens'); |
|
35 | + } |
|
36 | + if (class_exists('\PHP_CodeSniffer_Exception') === false) { |
|
37 | + class_alias('PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception'); |
|
38 | + } |
|
39 | + if (class_exists('\PHP_CodeSniffer_Standards_AbstractScopeSniff') === false) { |
|
40 | + class_alias('PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff'); |
|
41 | + } |
|
42 | + if (class_exists('\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff') === false) { |
|
43 | + class_alias('PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff', '\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff'); |
|
44 | + } |
|
45 | 45 | |
46 | - define('PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true); |
|
46 | + define('PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true); |
|
47 | 47 | |
48 | - /* |
|
48 | + /* |
|
49 | 49 | * Register an autoloader. |
50 | 50 | * |
51 | 51 | * {@internal When `installed_paths` is set via the ruleset, this autoloader |
52 | 52 | * is needed to run the sniffs. |
53 | 53 | * Upstream issue: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1591} }} |
54 | 54 | */ |
55 | - spl_autoload_register(function ($class) { |
|
56 | - // Only try & load our own classes. |
|
57 | - if (stripos($class, 'PHPCompatibility') !== 0) { |
|
58 | - return; |
|
59 | - } |
|
55 | + spl_autoload_register(function ($class) { |
|
56 | + // Only try & load our own classes. |
|
57 | + if (stripos($class, 'PHPCompatibility') !== 0) { |
|
58 | + return; |
|
59 | + } |
|
60 | 60 | |
61 | - $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; |
|
61 | + $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; |
|
62 | 62 | |
63 | - if (file_exists($file)) { |
|
64 | - include_once $file; |
|
65 | - } |
|
66 | - }); |
|
63 | + if (file_exists($file)) { |
|
64 | + include_once $file; |
|
65 | + } |
|
66 | + }); |
|
67 | 67 | } |
@@ -23,27 +23,27 @@ discard block |
||
23 | 23 | * external PHPCS standards creating cross-version compatibility in the same |
24 | 24 | * manner.}} |
25 | 25 | */ |
26 | -if (defined('PHPCOMPATIBILITY_PHPCS_ALIASES_SET') === false) { |
|
27 | - if (interface_exists('\PHP_CodeSniffer_Sniff') === false) { |
|
28 | - class_alias('PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff'); |
|
26 | +if ( defined( 'PHPCOMPATIBILITY_PHPCS_ALIASES_SET' ) === false ) { |
|
27 | + if ( interface_exists( '\PHP_CodeSniffer_Sniff' ) === false ) { |
|
28 | + class_alias( 'PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff' ); |
|
29 | 29 | } |
30 | - if (class_exists('\PHP_CodeSniffer_File') === false) { |
|
31 | - class_alias('PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File'); |
|
30 | + if ( class_exists( '\PHP_CodeSniffer_File' ) === false ) { |
|
31 | + class_alias( 'PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File' ); |
|
32 | 32 | } |
33 | - if (class_exists('\PHP_CodeSniffer_Tokens') === false) { |
|
34 | - class_alias('PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens'); |
|
33 | + if ( class_exists( '\PHP_CodeSniffer_Tokens' ) === false ) { |
|
34 | + class_alias( 'PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens' ); |
|
35 | 35 | } |
36 | - if (class_exists('\PHP_CodeSniffer_Exception') === false) { |
|
37 | - class_alias('PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception'); |
|
36 | + if ( class_exists( '\PHP_CodeSniffer_Exception' ) === false ) { |
|
37 | + class_alias( 'PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception' ); |
|
38 | 38 | } |
39 | - if (class_exists('\PHP_CodeSniffer_Standards_AbstractScopeSniff') === false) { |
|
40 | - class_alias('PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff'); |
|
39 | + if ( class_exists( '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ) === false ) { |
|
40 | + class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ); |
|
41 | 41 | } |
42 | - if (class_exists('\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff') === false) { |
|
43 | - class_alias('PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff', '\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff'); |
|
42 | + if ( class_exists( '\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff' ) === false ) { |
|
43 | + class_alias( 'PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff', '\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff' ); |
|
44 | 44 | } |
45 | 45 | |
46 | - define('PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true); |
|
46 | + define( 'PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true ); |
|
47 | 47 | |
48 | 48 | /* |
49 | 49 | * Register an autoloader. |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | * is needed to run the sniffs. |
53 | 53 | * Upstream issue: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1591} }} |
54 | 54 | */ |
55 | - spl_autoload_register(function ($class) { |
|
55 | + spl_autoload_register( function( $class ) { |
|
56 | 56 | // Only try & load our own classes. |
57 | - if (stripos($class, 'PHPCompatibility') !== 0) { |
|
57 | + if ( stripos( $class, 'PHPCompatibility' ) !== 0 ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; |
|
61 | + $file = realpath( __DIR__ ) . DIRECTORY_SEPARATOR . strtr( $class, '\\', DIRECTORY_SEPARATOR ) . '.php'; |
|
62 | 62 | |
63 | - if (file_exists($file)) { |
|
63 | + if ( file_exists( $file ) ) { |
|
64 | 64 | include_once $file; |
65 | 65 | } |
66 | 66 | }); |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
9 | - define('PHP_CODESNIFFER_IN_TESTS', true); |
|
9 | + define('PHP_CODESNIFFER_IN_TESTS', true); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // The below two defines are needed for PHPCS 3.x. |
13 | 13 | if (defined('PHP_CODESNIFFER_CBF') === false) { |
14 | - define('PHP_CODESNIFFER_CBF', false); |
|
14 | + define('PHP_CODESNIFFER_CBF', false); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | if (defined('PHP_CODESNIFFER_VERBOSITY') === false) { |
18 | - define('PHP_CODESNIFFER_VERBOSITY', 0); |
|
18 | + define('PHP_CODESNIFFER_VERBOSITY', 0); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | $ds = DIRECTORY_SEPARATOR; |
@@ -25,34 +25,34 @@ discard block |
||
25 | 25 | |
26 | 26 | // This may be a Composer install. |
27 | 27 | if ($phpcsDir === false && is_dir(__DIR__ . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer')) { |
28 | - $vendorDir = __DIR__ . $ds . 'vendor'; |
|
29 | - $phpcsDir = $vendorDir . $ds . 'squizlabs' . $ds . 'php_codesniffer'; |
|
28 | + $vendorDir = __DIR__ . $ds . 'vendor'; |
|
29 | + $phpcsDir = $vendorDir . $ds . 'squizlabs' . $ds . 'php_codesniffer'; |
|
30 | 30 | } elseif ($phpcsDir !== false) { |
31 | - $phpcsDir = realpath($phpcsDir); |
|
31 | + $phpcsDir = realpath($phpcsDir); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Try and load the PHPCS autoloader. |
35 | 35 | if ($phpcsDir !== false && file_exists($phpcsDir . $ds . 'autoload.php')) { |
36 | - // PHPCS 3.x. |
|
37 | - require_once $phpcsDir . $ds . 'autoload.php'; |
|
36 | + // PHPCS 3.x. |
|
37 | + require_once $phpcsDir . $ds . 'autoload.php'; |
|
38 | 38 | |
39 | - /* |
|
39 | + /* |
|
40 | 40 | * Alias the PHPCS 3.x classes to their PHPCS 2.x equivalent if necessary. |
41 | 41 | * Also provide a custom autoloader for our abstract base classes as the PHPCS native autoloader |
42 | 42 | * has trouble with them in combination with the PHPCompatibility custom unit test suite. |
43 | 43 | */ |
44 | - require_once __DIR__ . $ds . 'PHPCSAliases.php'; |
|
44 | + require_once __DIR__ . $ds . 'PHPCSAliases.php'; |
|
45 | 45 | |
46 | 46 | } elseif ($phpcsDir !== false && file_exists($phpcsDir . $ds . 'CodeSniffer.php')) { |
47 | - // PHPCS 2.x. |
|
48 | - require_once $phpcsDir . $ds . 'CodeSniffer.php'; |
|
47 | + // PHPCS 2.x. |
|
48 | + require_once $phpcsDir . $ds . 'CodeSniffer.php'; |
|
49 | 49 | |
50 | - if (isset($vendorDir) && file_exists($vendorDir . $ds . 'autoload.php')) { |
|
51 | - require_once $vendorDir . $ds . 'autoload.php'; |
|
52 | - } |
|
50 | + if (isset($vendorDir) && file_exists($vendorDir . $ds . 'autoload.php')) { |
|
51 | + require_once $vendorDir . $ds . 'autoload.php'; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } else { |
55 | - echo 'Uh oh... can\'t find PHPCS. |
|
55 | + echo 'Uh oh... can\'t find PHPCS. |
|
56 | 56 | |
57 | 57 | If you use Composer, please run `composer install --prefer-source`. |
58 | 58 | Otherwise, make sure you set a `PHPCS_DIR` environment variable in your phpunit.xml file |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | https://is.gd/PHPCompatibilityContrib |
63 | 63 | '; |
64 | 64 | |
65 | - die(1); |
|
65 | + die(1); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | 69 | // PHPUnit cross version compatibility. |
70 | 70 | if (class_exists('PHPUnit\Runner\Version') |
71 | - && version_compare(PHPUnit\Runner\Version::id(), '6.0', '>=') |
|
72 | - && class_exists('PHPUnit_Framework_TestCase') === false |
|
71 | + && version_compare(PHPUnit\Runner\Version::id(), '6.0', '>=') |
|
72 | + && class_exists('PHPUnit_Framework_TestCase') === false |
|
73 | 73 | ) { |
74 | - class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); |
|
74 | + class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | require_once __DIR__ . $ds . 'PHPCompatibility' . $ds . 'Tests' . $ds . 'BaseSniffTest.php'; |
@@ -5,34 +5,34 @@ discard block |
||
5 | 5 | * @package PHPCompatibility |
6 | 6 | */ |
7 | 7 | |
8 | -if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
|
9 | - define('PHP_CODESNIFFER_IN_TESTS', true); |
|
8 | +if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === false ) { |
|
9 | + define( 'PHP_CODESNIFFER_IN_TESTS', true ); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // The below two defines are needed for PHPCS 3.x. |
13 | -if (defined('PHP_CODESNIFFER_CBF') === false) { |
|
14 | - define('PHP_CODESNIFFER_CBF', false); |
|
13 | +if ( defined( 'PHP_CODESNIFFER_CBF' ) === false ) { |
|
14 | + define( 'PHP_CODESNIFFER_CBF', false ); |
|
15 | 15 | } |
16 | 16 | |
17 | -if (defined('PHP_CODESNIFFER_VERBOSITY') === false) { |
|
18 | - define('PHP_CODESNIFFER_VERBOSITY', 0); |
|
17 | +if ( defined( 'PHP_CODESNIFFER_VERBOSITY' ) === false ) { |
|
18 | + define( 'PHP_CODESNIFFER_VERBOSITY', 0 ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | $ds = DIRECTORY_SEPARATOR; |
22 | 22 | |
23 | 23 | // Get the PHPCS dir from an environment variable. |
24 | -$phpcsDir = getenv('PHPCS_DIR'); |
|
24 | +$phpcsDir = getenv( 'PHPCS_DIR' ); |
|
25 | 25 | |
26 | 26 | // This may be a Composer install. |
27 | -if ($phpcsDir === false && is_dir(__DIR__ . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer')) { |
|
27 | +if ( $phpcsDir === false && is_dir( __DIR__ . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer' ) ) { |
|
28 | 28 | $vendorDir = __DIR__ . $ds . 'vendor'; |
29 | 29 | $phpcsDir = $vendorDir . $ds . 'squizlabs' . $ds . 'php_codesniffer'; |
30 | -} elseif ($phpcsDir !== false) { |
|
31 | - $phpcsDir = realpath($phpcsDir); |
|
30 | +} elseif ( $phpcsDir !== false ) { |
|
31 | + $phpcsDir = realpath( $phpcsDir ); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Try and load the PHPCS autoloader. |
35 | -if ($phpcsDir !== false && file_exists($phpcsDir . $ds . 'autoload.php')) { |
|
35 | +if ( $phpcsDir !== false && file_exists( $phpcsDir . $ds . 'autoload.php' ) ) { |
|
36 | 36 | // PHPCS 3.x. |
37 | 37 | require_once $phpcsDir . $ds . 'autoload.php'; |
38 | 38 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | */ |
44 | 44 | require_once __DIR__ . $ds . 'PHPCSAliases.php'; |
45 | 45 | |
46 | -} elseif ($phpcsDir !== false && file_exists($phpcsDir . $ds . 'CodeSniffer.php')) { |
|
46 | +} elseif ( $phpcsDir !== false && file_exists( $phpcsDir . $ds . 'CodeSniffer.php' ) ) { |
|
47 | 47 | // PHPCS 2.x. |
48 | 48 | require_once $phpcsDir . $ds . 'CodeSniffer.php'; |
49 | 49 | |
50 | - if (isset($vendorDir) && file_exists($vendorDir . $ds . 'autoload.php')) { |
|
50 | + if ( isset( $vendorDir ) && file_exists( $vendorDir . $ds . 'autoload.php' ) ) { |
|
51 | 51 | require_once $vendorDir . $ds . 'autoload.php'; |
52 | 52 | } |
53 | 53 | |
@@ -62,18 +62,18 @@ discard block |
||
62 | 62 | https://is.gd/PHPCompatibilityContrib |
63 | 63 | '; |
64 | 64 | |
65 | - die(1); |
|
65 | + die( 1 ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | 69 | // PHPUnit cross version compatibility. |
70 | -if (class_exists('PHPUnit\Runner\Version') |
|
71 | - && version_compare(PHPUnit\Runner\Version::id(), '6.0', '>=') |
|
72 | - && class_exists('PHPUnit_Framework_TestCase') === false |
|
70 | +if ( class_exists( 'PHPUnit\Runner\Version' ) |
|
71 | + && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) |
|
72 | + && class_exists( 'PHPUnit_Framework_TestCase' ) === false |
|
73 | 73 | ) { |
74 | - class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); |
|
74 | + class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | require_once __DIR__ . $ds . 'PHPCompatibility' . $ds . 'Tests' . $ds . 'BaseSniffTest.php'; |
78 | 78 | require_once __DIR__ . $ds . 'PHPCompatibility' . $ds . 'Util' . $ds . 'Tests' . $ds . 'CoreMethodTestFrame.php'; |
79 | -unset($ds, $phpcsDir, $vendorDir); |
|
79 | +unset( $ds, $phpcsDir, $vendorDir ); |
@@ -34,445 +34,445 @@ |
||
34 | 34 | class Plugin implements PluginInterface, EventSubscriberInterface |
35 | 35 | { |
36 | 36 | |
37 | - const KEY_MAX_DEPTH = 'phpcodesniffer-search-depth'; |
|
38 | - |
|
39 | - const MESSAGE_ERROR_WRONG_MAX_DEPTH = |
|
40 | - 'The value of "%s" (in the composer.json "extra".section) must be an integer larger then %d, %s given.'; |
|
41 | - const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'; |
|
42 | - const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update'; |
|
43 | - const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; |
|
44 | - |
|
45 | - const PACKAGE_NAME = 'squizlabs/php_codesniffer'; |
|
46 | - const PACKAGE_TYPE = 'phpcodesniffer-standard'; |
|
47 | - |
|
48 | - const PHPCS_CONFIG_KEY = 'installed_paths'; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var Composer |
|
52 | - */ |
|
53 | - private $composer; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - private $cwd; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var Filesystem |
|
62 | - */ |
|
63 | - private $filesystem; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - private $installedPaths; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var IOInterface |
|
72 | - */ |
|
73 | - private $io; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var ProcessExecutor |
|
77 | - */ |
|
78 | - private $processExecutor; |
|
79 | - |
|
80 | - /** |
|
81 | - * Triggers the plugin's main functionality. |
|
82 | - * |
|
83 | - * Makes it possible to run the plugin as a custom command. |
|
84 | - * |
|
85 | - * @param Event $event |
|
86 | - * |
|
87 | - * @throws \InvalidArgumentException |
|
88 | - * @throws \RuntimeException |
|
89 | - * @throws LogicException |
|
90 | - * @throws ProcessFailedException |
|
91 | - * @throws RuntimeException |
|
92 | - */ |
|
93 | - public static function run(Event $event) |
|
94 | - { |
|
95 | - $io = $event->getIO(); |
|
96 | - $composer = $event->getComposer(); |
|
97 | - |
|
98 | - $instance = new static(); |
|
99 | - |
|
100 | - $instance->io = $io; |
|
101 | - $instance->composer = $composer; |
|
102 | - $instance->init(); |
|
103 | - $instance->onDependenciesChangedEvent(); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * {@inheritDoc} |
|
108 | - * |
|
109 | - * @throws \RuntimeException |
|
110 | - * @throws LogicException |
|
111 | - * @throws ProcessFailedException |
|
112 | - * @throws RuntimeException |
|
113 | - */ |
|
114 | - public function activate(Composer $composer, IOInterface $io) |
|
115 | - { |
|
116 | - $this->composer = $composer; |
|
117 | - $this->io = $io; |
|
118 | - |
|
119 | - $this->init(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Prepares the plugin so it's main functionality can be run. |
|
124 | - * |
|
125 | - * @throws \RuntimeException |
|
126 | - * @throws LogicException |
|
127 | - * @throws ProcessFailedException |
|
128 | - * @throws RuntimeException |
|
129 | - */ |
|
130 | - private function init() |
|
131 | - { |
|
132 | - $this->cwd = getcwd(); |
|
133 | - $this->installedPaths = array(); |
|
134 | - |
|
135 | - $this->processExecutor = new ProcessExecutor($this->io); |
|
136 | - $this->filesystem = new Filesystem($this->processExecutor); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * {@inheritDoc} |
|
141 | - */ |
|
142 | - public static function getSubscribedEvents() |
|
143 | - { |
|
144 | - return array( |
|
145 | - ScriptEvents::POST_INSTALL_CMD => array( |
|
146 | - array('onDependenciesChangedEvent', 0), |
|
147 | - ), |
|
148 | - ScriptEvents::POST_UPDATE_CMD => array( |
|
149 | - array('onDependenciesChangedEvent', 0), |
|
150 | - ), |
|
151 | - ); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Entry point for post install and post update events. |
|
156 | - * |
|
157 | - * @throws \InvalidArgumentException |
|
158 | - * @throws LogicException |
|
159 | - * @throws ProcessFailedException |
|
160 | - * @throws RuntimeException |
|
161 | - */ |
|
162 | - public function onDependenciesChangedEvent() |
|
163 | - { |
|
164 | - $io = $this->io; |
|
165 | - $isVerbose = $io->isVerbose(); |
|
166 | - |
|
167 | - if ($isVerbose) { |
|
168 | - $io->write(sprintf('<info>%s</info>', self::MESSAGE_RUNNING_INSTALLER)); |
|
169 | - } |
|
170 | - |
|
171 | - if ($this->isPHPCodeSnifferInstalled() === true) { |
|
172 | - $this->loadInstalledPaths(); |
|
173 | - $installPathCleaned = $this->cleanInstalledPaths(); |
|
174 | - $installPathUpdated = $this->updateInstalledPaths(); |
|
175 | - |
|
176 | - if ($installPathCleaned === true || $installPathUpdated === true) { |
|
177 | - $this->saveInstalledPaths(); |
|
178 | - } elseif ($isVerbose) { |
|
179 | - $io->write(sprintf('<info>%s</info>', self::MESSAGE_NOTHING_TO_INSTALL)); |
|
180 | - } |
|
181 | - } elseif ($isVerbose) { |
|
182 | - $io->write(sprintf('<info>%s</info>', self::MESSAGE_NOT_INSTALLED)); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Load all paths from PHP_CodeSniffer into an array. |
|
188 | - * |
|
189 | - * @throws LogicException |
|
190 | - * @throws ProcessFailedException |
|
191 | - * @throws RuntimeException |
|
192 | - */ |
|
193 | - private function loadInstalledPaths() |
|
194 | - { |
|
195 | - if ($this->isPHPCodeSnifferInstalled() === true) { |
|
196 | - $this->processExecutor->execute( |
|
197 | - sprintf( |
|
198 | - 'phpcs --config-show %s', |
|
199 | - self::PHPCS_CONFIG_KEY |
|
200 | - ), |
|
201 | - $output, |
|
202 | - $this->composer->getConfig()->get('bin-dir') |
|
203 | - ); |
|
204 | - |
|
205 | - $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output); |
|
206 | - $phpcsInstalledPaths = trim($phpcsInstalledPaths); |
|
207 | - |
|
208 | - if ($phpcsInstalledPaths !== '') { |
|
209 | - $this->installedPaths = explode(',', $phpcsInstalledPaths); |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Save all coding standard paths back into PHP_CodeSniffer |
|
216 | - * |
|
217 | - * @throws LogicException |
|
218 | - * @throws ProcessFailedException |
|
219 | - * @throws RuntimeException |
|
220 | - */ |
|
221 | - private function saveInstalledPaths() |
|
222 | - { |
|
223 | - // Check if we found installed paths to set. |
|
224 | - if (count($this->installedPaths) !== 0) { |
|
225 | - $paths = implode(',', $this->installedPaths); |
|
226 | - $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); |
|
227 | - $configMessage = sprintf( |
|
228 | - 'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>', |
|
229 | - self::PHPCS_CONFIG_KEY, |
|
230 | - $paths |
|
231 | - ); |
|
232 | - } else { |
|
233 | - // Delete the installed paths if none were found. |
|
234 | - $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); |
|
235 | - $configMessage = sprintf( |
|
236 | - 'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>', |
|
237 | - self::PHPCS_CONFIG_KEY |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - $this->io->write($configMessage); |
|
242 | - |
|
243 | - $this->processExecutor->execute( |
|
244 | - sprintf( |
|
245 | - 'phpcs %s', |
|
246 | - implode(' ', $arguments) |
|
247 | - ), |
|
248 | - $configResult, |
|
249 | - $this->composer->getConfig()->get('bin-dir') |
|
250 | - ); |
|
251 | - |
|
252 | - if ($this->io->isVerbose() && !empty($configResult)) { |
|
253 | - $this->io->write(sprintf('<info>%s</info>', $configResult)); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Iterate trough all known paths and check if they are still valid. |
|
259 | - * |
|
260 | - * If path does not exists, is not an directory or isn't readable, the path |
|
261 | - * is removed from the list. |
|
262 | - * |
|
263 | - * @return bool True if changes where made, false otherwise |
|
264 | - */ |
|
265 | - private function cleanInstalledPaths() |
|
266 | - { |
|
267 | - $changes = false; |
|
268 | - foreach ($this->installedPaths as $key => $path) { |
|
269 | - // This might be a relative path as well |
|
270 | - $alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path); |
|
271 | - |
|
272 | - if ((is_dir($path) === false || is_readable($path) === false) && |
|
273 | - (is_dir($alternativePath) === false || is_readable($alternativePath) === false) |
|
274 | - ) { |
|
275 | - unset($this->installedPaths[$key]); |
|
276 | - $changes = true; |
|
277 | - } |
|
278 | - } |
|
279 | - return $changes; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Check all installed packages (including the root package) against |
|
284 | - * the installed paths from PHP_CodeSniffer and add the missing ones. |
|
285 | - * |
|
286 | - * @return bool True if changes where made, false otherwise |
|
287 | - * |
|
288 | - * @throws \InvalidArgumentException |
|
289 | - * @throws \RuntimeException |
|
290 | - */ |
|
291 | - private function updateInstalledPaths() |
|
292 | - { |
|
293 | - $changes = false; |
|
294 | - |
|
295 | - $searchPaths = array($this->cwd); |
|
296 | - $codingStandardPackages = $this->getPHPCodingStandardPackages(); |
|
297 | - foreach ($codingStandardPackages as $package) { |
|
298 | - $installPath = $this->composer->getInstallationManager()->getInstallPath($package); |
|
299 | - if ($this->filesystem->isAbsolutePath($installPath) === false) { |
|
300 | - $installPath = $this->filesystem->normalizePath( |
|
301 | - $this->cwd . DIRECTORY_SEPARATOR . $installPath |
|
302 | - ); |
|
303 | - } |
|
304 | - $searchPaths[] = $installPath; |
|
305 | - } |
|
306 | - |
|
307 | - $finder = new Finder(); |
|
308 | - $finder->files() |
|
309 | - ->depth('<= ' . $this->getMaxDepth()) |
|
310 | - ->depth('>= ' . $this->getMinDepth()) |
|
311 | - ->ignoreUnreadableDirs() |
|
312 | - ->ignoreVCS(true) |
|
313 | - ->in($searchPaths) |
|
314 | - ->name('ruleset.xml'); |
|
315 | - |
|
316 | - // Process each found possible ruleset. |
|
317 | - foreach ($finder as $ruleset) { |
|
318 | - $standardsPath = $ruleset->getPath(); |
|
319 | - |
|
320 | - // Pick the directory above the directory containing the standard, unless this is the project root. |
|
321 | - if ($standardsPath !== $this->cwd) { |
|
322 | - $standardsPath = dirname($standardsPath); |
|
323 | - } |
|
324 | - |
|
325 | - // Use relative paths for local project repositories. |
|
326 | - if ($this->isRunningGlobally() === false) { |
|
327 | - $standardsPath = $this->filesystem->findShortestPath( |
|
328 | - $this->getPHPCodeSnifferInstallPath(), |
|
329 | - $standardsPath, |
|
330 | - true |
|
331 | - ); |
|
332 | - } |
|
333 | - |
|
334 | - // De-duplicate and add when directory is not configured. |
|
335 | - if (in_array($standardsPath, $this->installedPaths, true) === false) { |
|
336 | - $this->installedPaths[] = $standardsPath; |
|
337 | - $changes = true; |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - return $changes; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Iterates through Composers' local repository looking for valid Coding |
|
346 | - * Standard packages. |
|
347 | - * |
|
348 | - * If the package is the RootPackage (the one the plugin is installed into), |
|
349 | - * the package is ignored for now since it needs a different install path logic. |
|
350 | - * |
|
351 | - * @return array Composer packages containing coding standard(s) |
|
352 | - */ |
|
353 | - private function getPHPCodingStandardPackages() |
|
354 | - { |
|
355 | - $codingStandardPackages = array_filter( |
|
356 | - $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), |
|
357 | - function (PackageInterface $package) { |
|
358 | - if ($package instanceof AliasPackage) { |
|
359 | - return false; |
|
360 | - } |
|
361 | - return $package->getType() === Plugin::PACKAGE_TYPE; |
|
362 | - } |
|
363 | - ); |
|
364 | - |
|
365 | - if (! $this->composer->getPackage() instanceof RootpackageInterface |
|
366 | - && $this->composer->getPackage()->getType() === self::PACKAGE_TYPE |
|
367 | - ) { |
|
368 | - $codingStandardPackages[] = $this->composer->getPackage(); |
|
369 | - } |
|
370 | - |
|
371 | - return $codingStandardPackages; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Searches for the installed PHP_CodeSniffer Composer package |
|
376 | - * |
|
377 | - * @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against |
|
378 | - * |
|
379 | - * @return PackageInterface|null |
|
380 | - */ |
|
381 | - private function getPHPCodeSnifferPackage($versionConstraint = null) |
|
382 | - { |
|
383 | - $packages = $this |
|
384 | - ->composer |
|
385 | - ->getRepositoryManager() |
|
386 | - ->getLocalRepository() |
|
387 | - ->findPackages(self::PACKAGE_NAME, $versionConstraint); |
|
388 | - |
|
389 | - return array_shift($packages); |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns the path to the PHP_CodeSniffer package installation location |
|
394 | - * |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - private function getPHPCodeSnifferInstallPath() |
|
398 | - { |
|
399 | - return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage()); |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Simple check if PHP_CodeSniffer is installed. |
|
404 | - * |
|
405 | - * @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against |
|
406 | - * |
|
407 | - * @return bool Whether PHP_CodeSniffer is installed |
|
408 | - */ |
|
409 | - private function isPHPCodeSnifferInstalled($versionConstraint = null) |
|
410 | - { |
|
411 | - return ($this->getPHPCodeSnifferPackage($versionConstraint) !== null); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Test if composer is running "global" |
|
416 | - * This check kinda dirty, but it is the "Composer Way" |
|
417 | - * |
|
418 | - * @return bool Whether Composer is running "globally" |
|
419 | - * |
|
420 | - * @throws \RuntimeException |
|
421 | - */ |
|
422 | - private function isRunningGlobally() |
|
423 | - { |
|
424 | - return ($this->composer->getConfig()->get('home') === $this->cwd); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Determines the maximum search depth when searching for Coding Standards. |
|
429 | - * |
|
430 | - * @return int |
|
431 | - * |
|
432 | - * @throws \InvalidArgumentException |
|
433 | - */ |
|
434 | - private function getMaxDepth() |
|
435 | - { |
|
436 | - $maxDepth = 3; |
|
437 | - |
|
438 | - $extra = $this->composer->getPackage()->getExtra(); |
|
439 | - |
|
440 | - if (array_key_exists(self::KEY_MAX_DEPTH, $extra)) { |
|
441 | - $maxDepth = $extra[self::KEY_MAX_DEPTH]; |
|
442 | - $minDepth = $this->getMinDepth(); |
|
443 | - |
|
444 | - if (is_int($maxDepth) === false /* Must be an integer */ |
|
445 | - || $maxDepth <= $minDepth /* Larger than the minimum */ |
|
446 | - || is_float($maxDepth) === true /* Within the boundaries of integer */ |
|
447 | - ) { |
|
448 | - $message = vsprintf( |
|
449 | - self::MESSAGE_ERROR_WRONG_MAX_DEPTH, |
|
450 | - array( |
|
451 | - 'key' => self::KEY_MAX_DEPTH, |
|
452 | - 'min' => $minDepth, |
|
453 | - 'given' => var_export($maxDepth, true), |
|
454 | - ) |
|
455 | - ); |
|
456 | - |
|
457 | - throw new \InvalidArgumentException($message); |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - return $maxDepth; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the minimal search depth for Coding Standard packages. |
|
466 | - * |
|
467 | - * Usually this is 0, unless PHP_CodeSniffer >= 3 is used. |
|
468 | - * |
|
469 | - * @return int |
|
470 | - */ |
|
471 | - private function getMinDepth() |
|
472 | - { |
|
473 | - if ($this->isPHPCodeSnifferInstalled('>= 3.0.0') !== true) { |
|
474 | - return 1; |
|
475 | - } |
|
476 | - return 0; |
|
477 | - } |
|
37 | + const KEY_MAX_DEPTH = 'phpcodesniffer-search-depth'; |
|
38 | + |
|
39 | + const MESSAGE_ERROR_WRONG_MAX_DEPTH = |
|
40 | + 'The value of "%s" (in the composer.json "extra".section) must be an integer larger then %d, %s given.'; |
|
41 | + const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'; |
|
42 | + const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update'; |
|
43 | + const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; |
|
44 | + |
|
45 | + const PACKAGE_NAME = 'squizlabs/php_codesniffer'; |
|
46 | + const PACKAGE_TYPE = 'phpcodesniffer-standard'; |
|
47 | + |
|
48 | + const PHPCS_CONFIG_KEY = 'installed_paths'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var Composer |
|
52 | + */ |
|
53 | + private $composer; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + private $cwd; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var Filesystem |
|
62 | + */ |
|
63 | + private $filesystem; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + private $installedPaths; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var IOInterface |
|
72 | + */ |
|
73 | + private $io; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var ProcessExecutor |
|
77 | + */ |
|
78 | + private $processExecutor; |
|
79 | + |
|
80 | + /** |
|
81 | + * Triggers the plugin's main functionality. |
|
82 | + * |
|
83 | + * Makes it possible to run the plugin as a custom command. |
|
84 | + * |
|
85 | + * @param Event $event |
|
86 | + * |
|
87 | + * @throws \InvalidArgumentException |
|
88 | + * @throws \RuntimeException |
|
89 | + * @throws LogicException |
|
90 | + * @throws ProcessFailedException |
|
91 | + * @throws RuntimeException |
|
92 | + */ |
|
93 | + public static function run(Event $event) |
|
94 | + { |
|
95 | + $io = $event->getIO(); |
|
96 | + $composer = $event->getComposer(); |
|
97 | + |
|
98 | + $instance = new static(); |
|
99 | + |
|
100 | + $instance->io = $io; |
|
101 | + $instance->composer = $composer; |
|
102 | + $instance->init(); |
|
103 | + $instance->onDependenciesChangedEvent(); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * {@inheritDoc} |
|
108 | + * |
|
109 | + * @throws \RuntimeException |
|
110 | + * @throws LogicException |
|
111 | + * @throws ProcessFailedException |
|
112 | + * @throws RuntimeException |
|
113 | + */ |
|
114 | + public function activate(Composer $composer, IOInterface $io) |
|
115 | + { |
|
116 | + $this->composer = $composer; |
|
117 | + $this->io = $io; |
|
118 | + |
|
119 | + $this->init(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Prepares the plugin so it's main functionality can be run. |
|
124 | + * |
|
125 | + * @throws \RuntimeException |
|
126 | + * @throws LogicException |
|
127 | + * @throws ProcessFailedException |
|
128 | + * @throws RuntimeException |
|
129 | + */ |
|
130 | + private function init() |
|
131 | + { |
|
132 | + $this->cwd = getcwd(); |
|
133 | + $this->installedPaths = array(); |
|
134 | + |
|
135 | + $this->processExecutor = new ProcessExecutor($this->io); |
|
136 | + $this->filesystem = new Filesystem($this->processExecutor); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * {@inheritDoc} |
|
141 | + */ |
|
142 | + public static function getSubscribedEvents() |
|
143 | + { |
|
144 | + return array( |
|
145 | + ScriptEvents::POST_INSTALL_CMD => array( |
|
146 | + array('onDependenciesChangedEvent', 0), |
|
147 | + ), |
|
148 | + ScriptEvents::POST_UPDATE_CMD => array( |
|
149 | + array('onDependenciesChangedEvent', 0), |
|
150 | + ), |
|
151 | + ); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Entry point for post install and post update events. |
|
156 | + * |
|
157 | + * @throws \InvalidArgumentException |
|
158 | + * @throws LogicException |
|
159 | + * @throws ProcessFailedException |
|
160 | + * @throws RuntimeException |
|
161 | + */ |
|
162 | + public function onDependenciesChangedEvent() |
|
163 | + { |
|
164 | + $io = $this->io; |
|
165 | + $isVerbose = $io->isVerbose(); |
|
166 | + |
|
167 | + if ($isVerbose) { |
|
168 | + $io->write(sprintf('<info>%s</info>', self::MESSAGE_RUNNING_INSTALLER)); |
|
169 | + } |
|
170 | + |
|
171 | + if ($this->isPHPCodeSnifferInstalled() === true) { |
|
172 | + $this->loadInstalledPaths(); |
|
173 | + $installPathCleaned = $this->cleanInstalledPaths(); |
|
174 | + $installPathUpdated = $this->updateInstalledPaths(); |
|
175 | + |
|
176 | + if ($installPathCleaned === true || $installPathUpdated === true) { |
|
177 | + $this->saveInstalledPaths(); |
|
178 | + } elseif ($isVerbose) { |
|
179 | + $io->write(sprintf('<info>%s</info>', self::MESSAGE_NOTHING_TO_INSTALL)); |
|
180 | + } |
|
181 | + } elseif ($isVerbose) { |
|
182 | + $io->write(sprintf('<info>%s</info>', self::MESSAGE_NOT_INSTALLED)); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Load all paths from PHP_CodeSniffer into an array. |
|
188 | + * |
|
189 | + * @throws LogicException |
|
190 | + * @throws ProcessFailedException |
|
191 | + * @throws RuntimeException |
|
192 | + */ |
|
193 | + private function loadInstalledPaths() |
|
194 | + { |
|
195 | + if ($this->isPHPCodeSnifferInstalled() === true) { |
|
196 | + $this->processExecutor->execute( |
|
197 | + sprintf( |
|
198 | + 'phpcs --config-show %s', |
|
199 | + self::PHPCS_CONFIG_KEY |
|
200 | + ), |
|
201 | + $output, |
|
202 | + $this->composer->getConfig()->get('bin-dir') |
|
203 | + ); |
|
204 | + |
|
205 | + $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output); |
|
206 | + $phpcsInstalledPaths = trim($phpcsInstalledPaths); |
|
207 | + |
|
208 | + if ($phpcsInstalledPaths !== '') { |
|
209 | + $this->installedPaths = explode(',', $phpcsInstalledPaths); |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Save all coding standard paths back into PHP_CodeSniffer |
|
216 | + * |
|
217 | + * @throws LogicException |
|
218 | + * @throws ProcessFailedException |
|
219 | + * @throws RuntimeException |
|
220 | + */ |
|
221 | + private function saveInstalledPaths() |
|
222 | + { |
|
223 | + // Check if we found installed paths to set. |
|
224 | + if (count($this->installedPaths) !== 0) { |
|
225 | + $paths = implode(',', $this->installedPaths); |
|
226 | + $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); |
|
227 | + $configMessage = sprintf( |
|
228 | + 'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>', |
|
229 | + self::PHPCS_CONFIG_KEY, |
|
230 | + $paths |
|
231 | + ); |
|
232 | + } else { |
|
233 | + // Delete the installed paths if none were found. |
|
234 | + $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); |
|
235 | + $configMessage = sprintf( |
|
236 | + 'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>', |
|
237 | + self::PHPCS_CONFIG_KEY |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + $this->io->write($configMessage); |
|
242 | + |
|
243 | + $this->processExecutor->execute( |
|
244 | + sprintf( |
|
245 | + 'phpcs %s', |
|
246 | + implode(' ', $arguments) |
|
247 | + ), |
|
248 | + $configResult, |
|
249 | + $this->composer->getConfig()->get('bin-dir') |
|
250 | + ); |
|
251 | + |
|
252 | + if ($this->io->isVerbose() && !empty($configResult)) { |
|
253 | + $this->io->write(sprintf('<info>%s</info>', $configResult)); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Iterate trough all known paths and check if they are still valid. |
|
259 | + * |
|
260 | + * If path does not exists, is not an directory or isn't readable, the path |
|
261 | + * is removed from the list. |
|
262 | + * |
|
263 | + * @return bool True if changes where made, false otherwise |
|
264 | + */ |
|
265 | + private function cleanInstalledPaths() |
|
266 | + { |
|
267 | + $changes = false; |
|
268 | + foreach ($this->installedPaths as $key => $path) { |
|
269 | + // This might be a relative path as well |
|
270 | + $alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path); |
|
271 | + |
|
272 | + if ((is_dir($path) === false || is_readable($path) === false) && |
|
273 | + (is_dir($alternativePath) === false || is_readable($alternativePath) === false) |
|
274 | + ) { |
|
275 | + unset($this->installedPaths[$key]); |
|
276 | + $changes = true; |
|
277 | + } |
|
278 | + } |
|
279 | + return $changes; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Check all installed packages (including the root package) against |
|
284 | + * the installed paths from PHP_CodeSniffer and add the missing ones. |
|
285 | + * |
|
286 | + * @return bool True if changes where made, false otherwise |
|
287 | + * |
|
288 | + * @throws \InvalidArgumentException |
|
289 | + * @throws \RuntimeException |
|
290 | + */ |
|
291 | + private function updateInstalledPaths() |
|
292 | + { |
|
293 | + $changes = false; |
|
294 | + |
|
295 | + $searchPaths = array($this->cwd); |
|
296 | + $codingStandardPackages = $this->getPHPCodingStandardPackages(); |
|
297 | + foreach ($codingStandardPackages as $package) { |
|
298 | + $installPath = $this->composer->getInstallationManager()->getInstallPath($package); |
|
299 | + if ($this->filesystem->isAbsolutePath($installPath) === false) { |
|
300 | + $installPath = $this->filesystem->normalizePath( |
|
301 | + $this->cwd . DIRECTORY_SEPARATOR . $installPath |
|
302 | + ); |
|
303 | + } |
|
304 | + $searchPaths[] = $installPath; |
|
305 | + } |
|
306 | + |
|
307 | + $finder = new Finder(); |
|
308 | + $finder->files() |
|
309 | + ->depth('<= ' . $this->getMaxDepth()) |
|
310 | + ->depth('>= ' . $this->getMinDepth()) |
|
311 | + ->ignoreUnreadableDirs() |
|
312 | + ->ignoreVCS(true) |
|
313 | + ->in($searchPaths) |
|
314 | + ->name('ruleset.xml'); |
|
315 | + |
|
316 | + // Process each found possible ruleset. |
|
317 | + foreach ($finder as $ruleset) { |
|
318 | + $standardsPath = $ruleset->getPath(); |
|
319 | + |
|
320 | + // Pick the directory above the directory containing the standard, unless this is the project root. |
|
321 | + if ($standardsPath !== $this->cwd) { |
|
322 | + $standardsPath = dirname($standardsPath); |
|
323 | + } |
|
324 | + |
|
325 | + // Use relative paths for local project repositories. |
|
326 | + if ($this->isRunningGlobally() === false) { |
|
327 | + $standardsPath = $this->filesystem->findShortestPath( |
|
328 | + $this->getPHPCodeSnifferInstallPath(), |
|
329 | + $standardsPath, |
|
330 | + true |
|
331 | + ); |
|
332 | + } |
|
333 | + |
|
334 | + // De-duplicate and add when directory is not configured. |
|
335 | + if (in_array($standardsPath, $this->installedPaths, true) === false) { |
|
336 | + $this->installedPaths[] = $standardsPath; |
|
337 | + $changes = true; |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + return $changes; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Iterates through Composers' local repository looking for valid Coding |
|
346 | + * Standard packages. |
|
347 | + * |
|
348 | + * If the package is the RootPackage (the one the plugin is installed into), |
|
349 | + * the package is ignored for now since it needs a different install path logic. |
|
350 | + * |
|
351 | + * @return array Composer packages containing coding standard(s) |
|
352 | + */ |
|
353 | + private function getPHPCodingStandardPackages() |
|
354 | + { |
|
355 | + $codingStandardPackages = array_filter( |
|
356 | + $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), |
|
357 | + function (PackageInterface $package) { |
|
358 | + if ($package instanceof AliasPackage) { |
|
359 | + return false; |
|
360 | + } |
|
361 | + return $package->getType() === Plugin::PACKAGE_TYPE; |
|
362 | + } |
|
363 | + ); |
|
364 | + |
|
365 | + if (! $this->composer->getPackage() instanceof RootpackageInterface |
|
366 | + && $this->composer->getPackage()->getType() === self::PACKAGE_TYPE |
|
367 | + ) { |
|
368 | + $codingStandardPackages[] = $this->composer->getPackage(); |
|
369 | + } |
|
370 | + |
|
371 | + return $codingStandardPackages; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Searches for the installed PHP_CodeSniffer Composer package |
|
376 | + * |
|
377 | + * @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against |
|
378 | + * |
|
379 | + * @return PackageInterface|null |
|
380 | + */ |
|
381 | + private function getPHPCodeSnifferPackage($versionConstraint = null) |
|
382 | + { |
|
383 | + $packages = $this |
|
384 | + ->composer |
|
385 | + ->getRepositoryManager() |
|
386 | + ->getLocalRepository() |
|
387 | + ->findPackages(self::PACKAGE_NAME, $versionConstraint); |
|
388 | + |
|
389 | + return array_shift($packages); |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns the path to the PHP_CodeSniffer package installation location |
|
394 | + * |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + private function getPHPCodeSnifferInstallPath() |
|
398 | + { |
|
399 | + return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage()); |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Simple check if PHP_CodeSniffer is installed. |
|
404 | + * |
|
405 | + * @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against |
|
406 | + * |
|
407 | + * @return bool Whether PHP_CodeSniffer is installed |
|
408 | + */ |
|
409 | + private function isPHPCodeSnifferInstalled($versionConstraint = null) |
|
410 | + { |
|
411 | + return ($this->getPHPCodeSnifferPackage($versionConstraint) !== null); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Test if composer is running "global" |
|
416 | + * This check kinda dirty, but it is the "Composer Way" |
|
417 | + * |
|
418 | + * @return bool Whether Composer is running "globally" |
|
419 | + * |
|
420 | + * @throws \RuntimeException |
|
421 | + */ |
|
422 | + private function isRunningGlobally() |
|
423 | + { |
|
424 | + return ($this->composer->getConfig()->get('home') === $this->cwd); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Determines the maximum search depth when searching for Coding Standards. |
|
429 | + * |
|
430 | + * @return int |
|
431 | + * |
|
432 | + * @throws \InvalidArgumentException |
|
433 | + */ |
|
434 | + private function getMaxDepth() |
|
435 | + { |
|
436 | + $maxDepth = 3; |
|
437 | + |
|
438 | + $extra = $this->composer->getPackage()->getExtra(); |
|
439 | + |
|
440 | + if (array_key_exists(self::KEY_MAX_DEPTH, $extra)) { |
|
441 | + $maxDepth = $extra[self::KEY_MAX_DEPTH]; |
|
442 | + $minDepth = $this->getMinDepth(); |
|
443 | + |
|
444 | + if (is_int($maxDepth) === false /* Must be an integer */ |
|
445 | + || $maxDepth <= $minDepth /* Larger than the minimum */ |
|
446 | + || is_float($maxDepth) === true /* Within the boundaries of integer */ |
|
447 | + ) { |
|
448 | + $message = vsprintf( |
|
449 | + self::MESSAGE_ERROR_WRONG_MAX_DEPTH, |
|
450 | + array( |
|
451 | + 'key' => self::KEY_MAX_DEPTH, |
|
452 | + 'min' => $minDepth, |
|
453 | + 'given' => var_export($maxDepth, true), |
|
454 | + ) |
|
455 | + ); |
|
456 | + |
|
457 | + throw new \InvalidArgumentException($message); |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + return $maxDepth; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the minimal search depth for Coding Standard packages. |
|
466 | + * |
|
467 | + * Usually this is 0, unless PHP_CodeSniffer >= 3 is used. |
|
468 | + * |
|
469 | + * @return int |
|
470 | + */ |
|
471 | + private function getMinDepth() |
|
472 | + { |
|
473 | + if ($this->isPHPCodeSnifferInstalled('>= 3.0.0') !== true) { |
|
474 | + return 1; |
|
475 | + } |
|
476 | + return 0; |
|
477 | + } |
|
478 | 478 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @throws ProcessFailedException |
91 | 91 | * @throws RuntimeException |
92 | 92 | */ |
93 | - public static function run(Event $event) |
|
93 | + public static function run( Event $event ) |
|
94 | 94 | { |
95 | 95 | $io = $event->getIO(); |
96 | 96 | $composer = $event->getComposer(); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @throws ProcessFailedException |
112 | 112 | * @throws RuntimeException |
113 | 113 | */ |
114 | - public function activate(Composer $composer, IOInterface $io) |
|
114 | + public function activate( Composer $composer, IOInterface $io ) |
|
115 | 115 | { |
116 | 116 | $this->composer = $composer; |
117 | 117 | $this->io = $io; |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | $this->cwd = getcwd(); |
133 | 133 | $this->installedPaths = array(); |
134 | 134 | |
135 | - $this->processExecutor = new ProcessExecutor($this->io); |
|
136 | - $this->filesystem = new Filesystem($this->processExecutor); |
|
135 | + $this->processExecutor = new ProcessExecutor( $this->io ); |
|
136 | + $this->filesystem = new Filesystem( $this->processExecutor ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | { |
144 | 144 | return array( |
145 | 145 | ScriptEvents::POST_INSTALL_CMD => array( |
146 | - array('onDependenciesChangedEvent', 0), |
|
146 | + array( 'onDependenciesChangedEvent', 0 ), |
|
147 | 147 | ), |
148 | 148 | ScriptEvents::POST_UPDATE_CMD => array( |
149 | - array('onDependenciesChangedEvent', 0), |
|
149 | + array( 'onDependenciesChangedEvent', 0 ), |
|
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | } |
@@ -164,22 +164,22 @@ discard block |
||
164 | 164 | $io = $this->io; |
165 | 165 | $isVerbose = $io->isVerbose(); |
166 | 166 | |
167 | - if ($isVerbose) { |
|
168 | - $io->write(sprintf('<info>%s</info>', self::MESSAGE_RUNNING_INSTALLER)); |
|
167 | + if ( $isVerbose ) { |
|
168 | + $io->write( sprintf( '<info>%s</info>', self::MESSAGE_RUNNING_INSTALLER ) ); |
|
169 | 169 | } |
170 | 170 | |
171 | - if ($this->isPHPCodeSnifferInstalled() === true) { |
|
171 | + if ( $this->isPHPCodeSnifferInstalled() === true ) { |
|
172 | 172 | $this->loadInstalledPaths(); |
173 | 173 | $installPathCleaned = $this->cleanInstalledPaths(); |
174 | 174 | $installPathUpdated = $this->updateInstalledPaths(); |
175 | 175 | |
176 | - if ($installPathCleaned === true || $installPathUpdated === true) { |
|
176 | + if ( $installPathCleaned === true || $installPathUpdated === true ) { |
|
177 | 177 | $this->saveInstalledPaths(); |
178 | - } elseif ($isVerbose) { |
|
179 | - $io->write(sprintf('<info>%s</info>', self::MESSAGE_NOTHING_TO_INSTALL)); |
|
178 | + } elseif ( $isVerbose ) { |
|
179 | + $io->write( sprintf( '<info>%s</info>', self::MESSAGE_NOTHING_TO_INSTALL ) ); |
|
180 | 180 | } |
181 | - } elseif ($isVerbose) { |
|
182 | - $io->write(sprintf('<info>%s</info>', self::MESSAGE_NOT_INSTALLED)); |
|
181 | + } elseif ( $isVerbose ) { |
|
182 | + $io->write( sprintf( '<info>%s</info>', self::MESSAGE_NOT_INSTALLED ) ); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -192,21 +192,21 @@ discard block |
||
192 | 192 | */ |
193 | 193 | private function loadInstalledPaths() |
194 | 194 | { |
195 | - if ($this->isPHPCodeSnifferInstalled() === true) { |
|
195 | + if ( $this->isPHPCodeSnifferInstalled() === true ) { |
|
196 | 196 | $this->processExecutor->execute( |
197 | 197 | sprintf( |
198 | 198 | 'phpcs --config-show %s', |
199 | 199 | self::PHPCS_CONFIG_KEY |
200 | 200 | ), |
201 | 201 | $output, |
202 | - $this->composer->getConfig()->get('bin-dir') |
|
202 | + $this->composer->getConfig()->get( 'bin-dir' ) |
|
203 | 203 | ); |
204 | 204 | |
205 | - $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output); |
|
206 | - $phpcsInstalledPaths = trim($phpcsInstalledPaths); |
|
205 | + $phpcsInstalledPaths = str_replace( self::PHPCS_CONFIG_KEY . ': ', '', $output ); |
|
206 | + $phpcsInstalledPaths = trim( $phpcsInstalledPaths ); |
|
207 | 207 | |
208 | - if ($phpcsInstalledPaths !== '') { |
|
209 | - $this->installedPaths = explode(',', $phpcsInstalledPaths); |
|
208 | + if ( $phpcsInstalledPaths !== '' ) { |
|
209 | + $this->installedPaths = explode( ',', $phpcsInstalledPaths ); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | private function saveInstalledPaths() |
222 | 222 | { |
223 | 223 | // Check if we found installed paths to set. |
224 | - if (count($this->installedPaths) !== 0) { |
|
225 | - $paths = implode(',', $this->installedPaths); |
|
226 | - $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); |
|
224 | + if ( count( $this->installedPaths ) !== 0 ) { |
|
225 | + $paths = implode( ',', $this->installedPaths ); |
|
226 | + $arguments = array( '--config-set', self::PHPCS_CONFIG_KEY, $paths ); |
|
227 | 227 | $configMessage = sprintf( |
228 | 228 | 'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>', |
229 | 229 | self::PHPCS_CONFIG_KEY, |
@@ -231,26 +231,26 @@ discard block |
||
231 | 231 | ); |
232 | 232 | } else { |
233 | 233 | // Delete the installed paths if none were found. |
234 | - $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); |
|
234 | + $arguments = array( '--config-delete', self::PHPCS_CONFIG_KEY ); |
|
235 | 235 | $configMessage = sprintf( |
236 | 236 | 'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>', |
237 | 237 | self::PHPCS_CONFIG_KEY |
238 | 238 | ); |
239 | 239 | } |
240 | 240 | |
241 | - $this->io->write($configMessage); |
|
241 | + $this->io->write( $configMessage ); |
|
242 | 242 | |
243 | 243 | $this->processExecutor->execute( |
244 | 244 | sprintf( |
245 | 245 | 'phpcs %s', |
246 | - implode(' ', $arguments) |
|
246 | + implode( ' ', $arguments ) |
|
247 | 247 | ), |
248 | 248 | $configResult, |
249 | - $this->composer->getConfig()->get('bin-dir') |
|
249 | + $this->composer->getConfig()->get( 'bin-dir' ) |
|
250 | 250 | ); |
251 | 251 | |
252 | - if ($this->io->isVerbose() && !empty($configResult)) { |
|
253 | - $this->io->write(sprintf('<info>%s</info>', $configResult)); |
|
252 | + if ( $this->io->isVerbose() && ! empty( $configResult ) ) { |
|
253 | + $this->io->write( sprintf( '<info>%s</info>', $configResult ) ); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | private function cleanInstalledPaths() |
266 | 266 | { |
267 | 267 | $changes = false; |
268 | - foreach ($this->installedPaths as $key => $path) { |
|
268 | + foreach ( $this->installedPaths as $key => $path ) { |
|
269 | 269 | // This might be a relative path as well |
270 | - $alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path); |
|
270 | + $alternativePath = realpath( $this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path ); |
|
271 | 271 | |
272 | - if ((is_dir($path) === false || is_readable($path) === false) && |
|
273 | - (is_dir($alternativePath) === false || is_readable($alternativePath) === false) |
|
272 | + if ( ( is_dir( $path ) === false || is_readable( $path ) === false ) && |
|
273 | + ( is_dir( $alternativePath ) === false || is_readable( $alternativePath ) === false ) |
|
274 | 274 | ) { |
275 | - unset($this->installedPaths[$key]); |
|
275 | + unset( $this->installedPaths[ $key ] ); |
|
276 | 276 | $changes = true; |
277 | 277 | } |
278 | 278 | } |
@@ -292,38 +292,38 @@ discard block |
||
292 | 292 | { |
293 | 293 | $changes = false; |
294 | 294 | |
295 | - $searchPaths = array($this->cwd); |
|
295 | + $searchPaths = array( $this->cwd ); |
|
296 | 296 | $codingStandardPackages = $this->getPHPCodingStandardPackages(); |
297 | - foreach ($codingStandardPackages as $package) { |
|
298 | - $installPath = $this->composer->getInstallationManager()->getInstallPath($package); |
|
299 | - if ($this->filesystem->isAbsolutePath($installPath) === false) { |
|
297 | + foreach ( $codingStandardPackages as $package ) { |
|
298 | + $installPath = $this->composer->getInstallationManager()->getInstallPath( $package ); |
|
299 | + if ( $this->filesystem->isAbsolutePath( $installPath ) === false ) { |
|
300 | 300 | $installPath = $this->filesystem->normalizePath( |
301 | 301 | $this->cwd . DIRECTORY_SEPARATOR . $installPath |
302 | 302 | ); |
303 | 303 | } |
304 | - $searchPaths[] = $installPath; |
|
304 | + $searchPaths[ ] = $installPath; |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | $finder = new Finder(); |
308 | 308 | $finder->files() |
309 | - ->depth('<= ' . $this->getMaxDepth()) |
|
310 | - ->depth('>= ' . $this->getMinDepth()) |
|
309 | + ->depth( '<= ' . $this->getMaxDepth() ) |
|
310 | + ->depth( '>= ' . $this->getMinDepth() ) |
|
311 | 311 | ->ignoreUnreadableDirs() |
312 | - ->ignoreVCS(true) |
|
313 | - ->in($searchPaths) |
|
314 | - ->name('ruleset.xml'); |
|
312 | + ->ignoreVCS( true ) |
|
313 | + ->in( $searchPaths ) |
|
314 | + ->name( 'ruleset.xml' ); |
|
315 | 315 | |
316 | 316 | // Process each found possible ruleset. |
317 | - foreach ($finder as $ruleset) { |
|
317 | + foreach ( $finder as $ruleset ) { |
|
318 | 318 | $standardsPath = $ruleset->getPath(); |
319 | 319 | |
320 | 320 | // Pick the directory above the directory containing the standard, unless this is the project root. |
321 | - if ($standardsPath !== $this->cwd) { |
|
322 | - $standardsPath = dirname($standardsPath); |
|
321 | + if ( $standardsPath !== $this->cwd ) { |
|
322 | + $standardsPath = dirname( $standardsPath ); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // Use relative paths for local project repositories. |
326 | - if ($this->isRunningGlobally() === false) { |
|
326 | + if ( $this->isRunningGlobally() === false ) { |
|
327 | 327 | $standardsPath = $this->filesystem->findShortestPath( |
328 | 328 | $this->getPHPCodeSnifferInstallPath(), |
329 | 329 | $standardsPath, |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | } |
333 | 333 | |
334 | 334 | // De-duplicate and add when directory is not configured. |
335 | - if (in_array($standardsPath, $this->installedPaths, true) === false) { |
|
336 | - $this->installedPaths[] = $standardsPath; |
|
335 | + if ( in_array( $standardsPath, $this->installedPaths, true ) === false ) { |
|
336 | + $this->installedPaths[ ] = $standardsPath; |
|
337 | 337 | $changes = true; |
338 | 338 | } |
339 | 339 | } |
@@ -354,18 +354,18 @@ discard block |
||
354 | 354 | { |
355 | 355 | $codingStandardPackages = array_filter( |
356 | 356 | $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), |
357 | - function (PackageInterface $package) { |
|
358 | - if ($package instanceof AliasPackage) { |
|
357 | + function( PackageInterface $package ) { |
|
358 | + if ( $package instanceof AliasPackage ) { |
|
359 | 359 | return false; |
360 | 360 | } |
361 | 361 | return $package->getType() === Plugin::PACKAGE_TYPE; |
362 | 362 | } |
363 | 363 | ); |
364 | 364 | |
365 | - if (! $this->composer->getPackage() instanceof RootpackageInterface |
|
365 | + if ( ! $this->composer->getPackage() instanceof RootpackageInterface |
|
366 | 366 | && $this->composer->getPackage()->getType() === self::PACKAGE_TYPE |
367 | 367 | ) { |
368 | - $codingStandardPackages[] = $this->composer->getPackage(); |
|
368 | + $codingStandardPackages[ ] = $this->composer->getPackage(); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | return $codingStandardPackages; |
@@ -378,15 +378,15 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @return PackageInterface|null |
380 | 380 | */ |
381 | - private function getPHPCodeSnifferPackage($versionConstraint = null) |
|
381 | + private function getPHPCodeSnifferPackage( $versionConstraint = null ) |
|
382 | 382 | { |
383 | 383 | $packages = $this |
384 | 384 | ->composer |
385 | 385 | ->getRepositoryManager() |
386 | 386 | ->getLocalRepository() |
387 | - ->findPackages(self::PACKAGE_NAME, $versionConstraint); |
|
387 | + ->findPackages( self::PACKAGE_NAME, $versionConstraint ); |
|
388 | 388 | |
389 | - return array_shift($packages); |
|
389 | + return array_shift( $packages ); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | */ |
397 | 397 | private function getPHPCodeSnifferInstallPath() |
398 | 398 | { |
399 | - return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage()); |
|
399 | + return $this->composer->getInstallationManager()->getInstallPath( $this->getPHPCodeSnifferPackage() ); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -406,9 +406,9 @@ discard block |
||
406 | 406 | * |
407 | 407 | * @return bool Whether PHP_CodeSniffer is installed |
408 | 408 | */ |
409 | - private function isPHPCodeSnifferInstalled($versionConstraint = null) |
|
409 | + private function isPHPCodeSnifferInstalled( $versionConstraint = null ) |
|
410 | 410 | { |
411 | - return ($this->getPHPCodeSnifferPackage($versionConstraint) !== null); |
|
411 | + return ( $this->getPHPCodeSnifferPackage( $versionConstraint ) !== null ); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | */ |
422 | 422 | private function isRunningGlobally() |
423 | 423 | { |
424 | - return ($this->composer->getConfig()->get('home') === $this->cwd); |
|
424 | + return ( $this->composer->getConfig()->get( 'home' ) === $this->cwd ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -437,24 +437,24 @@ discard block |
||
437 | 437 | |
438 | 438 | $extra = $this->composer->getPackage()->getExtra(); |
439 | 439 | |
440 | - if (array_key_exists(self::KEY_MAX_DEPTH, $extra)) { |
|
441 | - $maxDepth = $extra[self::KEY_MAX_DEPTH]; |
|
440 | + if ( array_key_exists( self::KEY_MAX_DEPTH, $extra ) ) { |
|
441 | + $maxDepth = $extra[ self::KEY_MAX_DEPTH ]; |
|
442 | 442 | $minDepth = $this->getMinDepth(); |
443 | 443 | |
444 | - if (is_int($maxDepth) === false /* Must be an integer */ |
|
444 | + if ( is_int( $maxDepth ) === false /* Must be an integer */ |
|
445 | 445 | || $maxDepth <= $minDepth /* Larger than the minimum */ |
446 | - || is_float($maxDepth) === true /* Within the boundaries of integer */ |
|
446 | + || is_float( $maxDepth ) === true /* Within the boundaries of integer */ |
|
447 | 447 | ) { |
448 | 448 | $message = vsprintf( |
449 | 449 | self::MESSAGE_ERROR_WRONG_MAX_DEPTH, |
450 | 450 | array( |
451 | 451 | 'key' => self::KEY_MAX_DEPTH, |
452 | 452 | 'min' => $minDepth, |
453 | - 'given' => var_export($maxDepth, true), |
|
453 | + 'given' => var_export( $maxDepth, true ), |
|
454 | 454 | ) |
455 | 455 | ); |
456 | 456 | |
457 | - throw new \InvalidArgumentException($message); |
|
457 | + throw new \InvalidArgumentException( $message ); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | */ |
471 | 471 | private function getMinDepth() |
472 | 472 | { |
473 | - if ($this->isPHPCodeSnifferInstalled('>= 3.0.0') !== true) { |
|
473 | + if ( $this->isPHPCodeSnifferInstalled( '>= 3.0.0' ) !== true ) { |
|
474 | 474 | return 1; |
475 | 475 | } |
476 | 476 | return 0; |
@@ -90,8 +90,7 @@ discard block |
||
90 | 90 | * @throws ProcessFailedException |
91 | 91 | * @throws RuntimeException |
92 | 92 | */ |
93 | - public static function run(Event $event) |
|
94 | - { |
|
93 | + public static function run(Event $event) { |
|
95 | 94 | $io = $event->getIO(); |
96 | 95 | $composer = $event->getComposer(); |
97 | 96 | |
@@ -111,8 +110,7 @@ discard block |
||
111 | 110 | * @throws ProcessFailedException |
112 | 111 | * @throws RuntimeException |
113 | 112 | */ |
114 | - public function activate(Composer $composer, IOInterface $io) |
|
115 | - { |
|
113 | + public function activate(Composer $composer, IOInterface $io) { |
|
116 | 114 | $this->composer = $composer; |
117 | 115 | $this->io = $io; |
118 | 116 | |
@@ -127,8 +125,7 @@ discard block |
||
127 | 125 | * @throws ProcessFailedException |
128 | 126 | * @throws RuntimeException |
129 | 127 | */ |
130 | - private function init() |
|
131 | - { |
|
128 | + private function init() { |
|
132 | 129 | $this->cwd = getcwd(); |
133 | 130 | $this->installedPaths = array(); |
134 | 131 | |
@@ -139,8 +136,7 @@ discard block |
||
139 | 136 | /** |
140 | 137 | * {@inheritDoc} |
141 | 138 | */ |
142 | - public static function getSubscribedEvents() |
|
143 | - { |
|
139 | + public static function getSubscribedEvents() { |
|
144 | 140 | return array( |
145 | 141 | ScriptEvents::POST_INSTALL_CMD => array( |
146 | 142 | array('onDependenciesChangedEvent', 0), |
@@ -159,8 +155,7 @@ discard block |
||
159 | 155 | * @throws ProcessFailedException |
160 | 156 | * @throws RuntimeException |
161 | 157 | */ |
162 | - public function onDependenciesChangedEvent() |
|
163 | - { |
|
158 | + public function onDependenciesChangedEvent() { |
|
164 | 159 | $io = $this->io; |
165 | 160 | $isVerbose = $io->isVerbose(); |
166 | 161 | |
@@ -190,8 +185,7 @@ discard block |
||
190 | 185 | * @throws ProcessFailedException |
191 | 186 | * @throws RuntimeException |
192 | 187 | */ |
193 | - private function loadInstalledPaths() |
|
194 | - { |
|
188 | + private function loadInstalledPaths() { |
|
195 | 189 | if ($this->isPHPCodeSnifferInstalled() === true) { |
196 | 190 | $this->processExecutor->execute( |
197 | 191 | sprintf( |
@@ -218,8 +212,7 @@ discard block |
||
218 | 212 | * @throws ProcessFailedException |
219 | 213 | * @throws RuntimeException |
220 | 214 | */ |
221 | - private function saveInstalledPaths() |
|
222 | - { |
|
215 | + private function saveInstalledPaths() { |
|
223 | 216 | // Check if we found installed paths to set. |
224 | 217 | if (count($this->installedPaths) !== 0) { |
225 | 218 | $paths = implode(',', $this->installedPaths); |
@@ -262,8 +255,7 @@ discard block |
||
262 | 255 | * |
263 | 256 | * @return bool True if changes where made, false otherwise |
264 | 257 | */ |
265 | - private function cleanInstalledPaths() |
|
266 | - { |
|
258 | + private function cleanInstalledPaths() { |
|
267 | 259 | $changes = false; |
268 | 260 | foreach ($this->installedPaths as $key => $path) { |
269 | 261 | // This might be a relative path as well |
@@ -288,8 +280,7 @@ discard block |
||
288 | 280 | * @throws \InvalidArgumentException |
289 | 281 | * @throws \RuntimeException |
290 | 282 | */ |
291 | - private function updateInstalledPaths() |
|
292 | - { |
|
283 | + private function updateInstalledPaths() { |
|
293 | 284 | $changes = false; |
294 | 285 | |
295 | 286 | $searchPaths = array($this->cwd); |
@@ -350,8 +341,7 @@ discard block |
||
350 | 341 | * |
351 | 342 | * @return array Composer packages containing coding standard(s) |
352 | 343 | */ |
353 | - private function getPHPCodingStandardPackages() |
|
354 | - { |
|
344 | + private function getPHPCodingStandardPackages() { |
|
355 | 345 | $codingStandardPackages = array_filter( |
356 | 346 | $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), |
357 | 347 | function (PackageInterface $package) { |
@@ -378,8 +368,7 @@ discard block |
||
378 | 368 | * |
379 | 369 | * @return PackageInterface|null |
380 | 370 | */ |
381 | - private function getPHPCodeSnifferPackage($versionConstraint = null) |
|
382 | - { |
|
371 | + private function getPHPCodeSnifferPackage($versionConstraint = null) { |
|
383 | 372 | $packages = $this |
384 | 373 | ->composer |
385 | 374 | ->getRepositoryManager() |
@@ -394,8 +383,7 @@ discard block |
||
394 | 383 | * |
395 | 384 | * @return string |
396 | 385 | */ |
397 | - private function getPHPCodeSnifferInstallPath() |
|
398 | - { |
|
386 | + private function getPHPCodeSnifferInstallPath() { |
|
399 | 387 | return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage()); |
400 | 388 | } |
401 | 389 | |
@@ -406,8 +394,7 @@ discard block |
||
406 | 394 | * |
407 | 395 | * @return bool Whether PHP_CodeSniffer is installed |
408 | 396 | */ |
409 | - private function isPHPCodeSnifferInstalled($versionConstraint = null) |
|
410 | - { |
|
397 | + private function isPHPCodeSnifferInstalled($versionConstraint = null) { |
|
411 | 398 | return ($this->getPHPCodeSnifferPackage($versionConstraint) !== null); |
412 | 399 | } |
413 | 400 | |
@@ -419,8 +406,7 @@ discard block |
||
419 | 406 | * |
420 | 407 | * @throws \RuntimeException |
421 | 408 | */ |
422 | - private function isRunningGlobally() |
|
423 | - { |
|
409 | + private function isRunningGlobally() { |
|
424 | 410 | return ($this->composer->getConfig()->get('home') === $this->cwd); |
425 | 411 | } |
426 | 412 | |
@@ -431,8 +417,7 @@ discard block |
||
431 | 417 | * |
432 | 418 | * @throws \InvalidArgumentException |
433 | 419 | */ |
434 | - private function getMaxDepth() |
|
435 | - { |
|
420 | + private function getMaxDepth() { |
|
436 | 421 | $maxDepth = 3; |
437 | 422 | |
438 | 423 | $extra = $this->composer->getPackage()->getExtra(); |
@@ -468,8 +453,7 @@ discard block |
||
468 | 453 | * |
469 | 454 | * @return int |
470 | 455 | */ |
471 | - private function getMinDepth() |
|
472 | - { |
|
456 | + private function getMinDepth() { |
|
473 | 457 | if ($this->isPHPCodeSnifferInstalled('>= 3.0.0') !== true) { |
474 | 458 | return 1; |
475 | 459 | } |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | unset( $this->groups[ $groupName ] ); |
154 | 154 | } else { |
155 | 155 | $items = array_map( array( $this, 'prepare_name_for_regex' ), $group[ $key ] ); |
156 | - $all_items[] = $items; |
|
156 | + $all_items[ ] = $items; |
|
157 | 157 | $items = implode( '|', $items ); |
158 | 158 | |
159 | - $this->groups[ $groupName ]['regex'] = sprintf( $this->regex_pattern, $items ); |
|
159 | + $this->groups[ $groupName ][ 'regex' ] = sprintf( $this->regex_pattern, $items ); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | // Preliminary check. If the content of the T_STRING is not one of the functions we're |
193 | 193 | // looking for, we can bow out before doing the heavy lifting of checking whether |
194 | 194 | // this is a function call. |
195 | - if ( preg_match( $this->prelim_check_regex, $this->tokens[ $stackPtr ]['content'] ) !== 1 ) { |
|
195 | + if ( preg_match( $this->prelim_check_regex, $this->tokens[ $stackPtr ][ 'content' ] ) !== 1 ) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | public function is_targetted_token( $stackPtr ) { |
214 | 214 | |
215 | 215 | // Exclude function definitions, class methods, and namespaced calls. |
216 | - if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) { |
|
216 | + if ( \T_STRING === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
217 | 217 | if ( $this->is_class_object_call( $stackPtr ) === true ) { |
218 | 218 | return false; |
219 | 219 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | \T_AS => \T_AS, // Use declaration alias. |
233 | 233 | ); |
234 | 234 | |
235 | - if ( isset( $skipped[ $this->tokens[ $prev ]['code'] ] ) ) { |
|
235 | + if ( isset( $skipped[ $this->tokens[ $prev ][ 'code' ] ] ) ) { |
|
236 | 236 | return false; |
237 | 237 | } |
238 | 238 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * normal file processing. |
255 | 255 | */ |
256 | 256 | public function check_for_matches( $stackPtr ) { |
257 | - $token_content = strtolower( $this->tokens[ $stackPtr ]['content'] ); |
|
257 | + $token_content = strtolower( $this->tokens[ $stackPtr ][ 'content' ] ); |
|
258 | 258 | $skip_to = array(); |
259 | 259 | |
260 | 260 | foreach ( $this->groups as $groupName => $group ) { |
@@ -263,12 +263,12 @@ discard block |
||
263 | 263 | continue; |
264 | 264 | } |
265 | 265 | |
266 | - if ( isset( $group['whitelist'][ $token_content ] ) ) { |
|
266 | + if ( isset( $group[ 'whitelist' ][ $token_content ] ) ) { |
|
267 | 267 | continue; |
268 | 268 | } |
269 | 269 | |
270 | - if ( preg_match( $group['regex'], $token_content ) === 1 ) { |
|
271 | - $skip_to[] = $this->process_matched_token( $stackPtr, $groupName, $token_content ); |
|
270 | + if ( preg_match( $group[ 'regex' ], $token_content ) === 1 ) { |
|
271 | + $skip_to[ ] = $this->process_matched_token( $stackPtr, $groupName, $token_content ); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | public function process_matched_token( $stackPtr, $group_name, $matched_content ) { |
295 | 295 | |
296 | 296 | $this->addMessage( |
297 | - $this->groups[ $group_name ]['message'], |
|
297 | + $this->groups[ $group_name ][ 'message' ], |
|
298 | 298 | $stackPtr, |
299 | - ( 'error' === $this->groups[ $group_name ]['type'] ), |
|
299 | + ( 'error' === $this->groups[ $group_name ][ 'type' ] ), |
|
300 | 300 | $this->string_to_errorcode( $group_name . '_' . $matched_content ), |
301 | 301 | array( $matched_content ) |
302 | 302 | ); |
@@ -8,40 +8,40 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
11 | - define('PHP_CODESNIFFER_IN_TESTS', true); |
|
11 | + define('PHP_CODESNIFFER_IN_TESTS', true); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | if (defined('PHP_CODESNIFFER_CBF') === false) { |
15 | - define('PHP_CODESNIFFER_CBF', false); |
|
15 | + define('PHP_CODESNIFFER_CBF', false); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | if (defined('PHP_CODESNIFFER_VERBOSITY') === false) { |
19 | - define('PHP_CODESNIFFER_VERBOSITY', 0); |
|
19 | + define('PHP_CODESNIFFER_VERBOSITY', 0); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if (is_file(__DIR__.'/../autoload.php') === true) { |
23 | - include_once __DIR__.'/../autoload.php'; |
|
23 | + include_once __DIR__.'/../autoload.php'; |
|
24 | 24 | } else { |
25 | - include_once 'PHP/CodeSniffer/autoload.php'; |
|
25 | + include_once 'PHP/CodeSniffer/autoload.php'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $tokens = new \PHP_CodeSniffer\Util\Tokens(); |
29 | 29 | |
30 | 30 | // Compatibility for PHPUnit < 6 and PHPUnit 6+. |
31 | 31 | if (class_exists('PHPUnit_Framework_TestSuite') === true && class_exists('PHPUnit\Framework\TestSuite') === false) { |
32 | - class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit'.'\Framework\TestSuite'); |
|
32 | + class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit'.'\Framework\TestSuite'); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | if (class_exists('PHPUnit_Framework_TestCase') === true && class_exists('PHPUnit\Framework\TestCase') === false) { |
36 | - class_alias('PHPUnit_Framework_TestCase', 'PHPUnit'.'\Framework\TestCase'); |
|
36 | + class_alias('PHPUnit_Framework_TestCase', 'PHPUnit'.'\Framework\TestCase'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | if (class_exists('PHPUnit_TextUI_TestRunner') === true && class_exists('PHPUnit\TextUI\TestRunner') === false) { |
40 | - class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner'); |
|
40 | + class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | if (class_exists('PHPUnit_Framework_TestResult') === true && class_exists('PHPUnit\Framework\TestResult') === false) { |
44 | - class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult'); |
|
44 | + class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult'); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
@@ -52,33 +52,33 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function printPHPCodeSnifferTestOutput() |
54 | 54 | { |
55 | - echo PHP_EOL.PHP_EOL; |
|
55 | + echo PHP_EOL.PHP_EOL; |
|
56 | 56 | |
57 | - $output = 'The test files'; |
|
58 | - $data = []; |
|
57 | + $output = 'The test files'; |
|
58 | + $data = []; |
|
59 | 59 | |
60 | - $codeCount = count($GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']); |
|
61 | - if (empty($GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']) === false) { |
|
62 | - $files = call_user_func_array('array_merge', $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']); |
|
63 | - $files = array_unique($files); |
|
64 | - $fileCount = count($files); |
|
60 | + $codeCount = count($GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']); |
|
61 | + if (empty($GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']) === false) { |
|
62 | + $files = call_user_func_array('array_merge', $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']); |
|
63 | + $files = array_unique($files); |
|
64 | + $fileCount = count($files); |
|
65 | 65 | |
66 | - $output = '%d sniff test files'; |
|
67 | - $data[] = $fileCount; |
|
68 | - } |
|
66 | + $output = '%d sniff test files'; |
|
67 | + $data[] = $fileCount; |
|
68 | + } |
|
69 | 69 | |
70 | - $output .= ' generated %d unique error codes'; |
|
71 | - $data[] = $codeCount; |
|
70 | + $output .= ' generated %d unique error codes'; |
|
71 | + $data[] = $codeCount; |
|
72 | 72 | |
73 | - if ($codeCount > 0) { |
|
74 | - $fixes = count($GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']); |
|
75 | - $percent = round(($fixes / $codeCount * 100), 2); |
|
73 | + if ($codeCount > 0) { |
|
74 | + $fixes = count($GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']); |
|
75 | + $percent = round(($fixes / $codeCount * 100), 2); |
|
76 | 76 | |
77 | - $output .= '; %d were fixable (%d%%)'; |
|
78 | - $data[] = $fixes; |
|
79 | - $data[] = $percent; |
|
80 | - } |
|
77 | + $output .= '; %d were fixable (%d%%)'; |
|
78 | + $data[] = $fixes; |
|
79 | + $data[] = $percent; |
|
80 | + } |
|
81 | 81 | |
82 | - vprintf($output, $data); |
|
82 | + vprintf($output, $data); |
|
83 | 83 | |
84 | 84 | }//end printPHPCodeSnifferTestOutput() |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
8 | 8 | */ |
9 | 9 | |
10 | -if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
|
11 | - define('PHP_CODESNIFFER_IN_TESTS', true); |
|
10 | +if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === false ) { |
|
11 | + define( 'PHP_CODESNIFFER_IN_TESTS', true ); |
|
12 | 12 | } |
13 | 13 | |
14 | -if (defined('PHP_CODESNIFFER_CBF') === false) { |
|
15 | - define('PHP_CODESNIFFER_CBF', false); |
|
14 | +if ( defined( 'PHP_CODESNIFFER_CBF' ) === false ) { |
|
15 | + define( 'PHP_CODESNIFFER_CBF', false ); |
|
16 | 16 | } |
17 | 17 | |
18 | -if (defined('PHP_CODESNIFFER_VERBOSITY') === false) { |
|
19 | - define('PHP_CODESNIFFER_VERBOSITY', 0); |
|
18 | +if ( defined( 'PHP_CODESNIFFER_VERBOSITY' ) === false ) { |
|
19 | + define( 'PHP_CODESNIFFER_VERBOSITY', 0 ); |
|
20 | 20 | } |
21 | 21 | |
22 | -if (is_file(__DIR__.'/../autoload.php') === true) { |
|
23 | - include_once __DIR__.'/../autoload.php'; |
|
22 | +if ( is_file( __DIR__ . '/../autoload.php' ) === true ) { |
|
23 | + include_once __DIR__ . '/../autoload.php'; |
|
24 | 24 | } else { |
25 | 25 | include_once 'PHP/CodeSniffer/autoload.php'; |
26 | 26 | } |
@@ -28,20 +28,20 @@ discard block |
||
28 | 28 | $tokens = new \PHP_CodeSniffer\Util\Tokens(); |
29 | 29 | |
30 | 30 | // Compatibility for PHPUnit < 6 and PHPUnit 6+. |
31 | -if (class_exists('PHPUnit_Framework_TestSuite') === true && class_exists('PHPUnit\Framework\TestSuite') === false) { |
|
32 | - class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit'.'\Framework\TestSuite'); |
|
31 | +if ( class_exists( 'PHPUnit_Framework_TestSuite' ) === true && class_exists( 'PHPUnit\Framework\TestSuite' ) === false ) { |
|
32 | + class_alias( 'PHPUnit_Framework_TestSuite', 'PHPUnit' . '\Framework\TestSuite' ); |
|
33 | 33 | } |
34 | 34 | |
35 | -if (class_exists('PHPUnit_Framework_TestCase') === true && class_exists('PHPUnit\Framework\TestCase') === false) { |
|
36 | - class_alias('PHPUnit_Framework_TestCase', 'PHPUnit'.'\Framework\TestCase'); |
|
35 | +if ( class_exists( 'PHPUnit_Framework_TestCase' ) === true && class_exists( 'PHPUnit\Framework\TestCase' ) === false ) { |
|
36 | + class_alias( 'PHPUnit_Framework_TestCase', 'PHPUnit' . '\Framework\TestCase' ); |
|
37 | 37 | } |
38 | 38 | |
39 | -if (class_exists('PHPUnit_TextUI_TestRunner') === true && class_exists('PHPUnit\TextUI\TestRunner') === false) { |
|
40 | - class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner'); |
|
39 | +if ( class_exists( 'PHPUnit_TextUI_TestRunner' ) === true && class_exists( 'PHPUnit\TextUI\TestRunner' ) === false ) { |
|
40 | + class_alias( 'PHPUnit_TextUI_TestRunner', 'PHPUnit' . '\TextUI\TestRunner' ); |
|
41 | 41 | } |
42 | 42 | |
43 | -if (class_exists('PHPUnit_Framework_TestResult') === true && class_exists('PHPUnit\Framework\TestResult') === false) { |
|
44 | - class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult'); |
|
43 | +if ( class_exists( 'PHPUnit_Framework_TestResult' ) === true && class_exists( 'PHPUnit\Framework\TestResult' ) === false ) { |
|
44 | + class_alias( 'PHPUnit_Framework_TestResult', 'PHPUnit' . '\Framework\TestResult' ); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
@@ -52,33 +52,33 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function printPHPCodeSnifferTestOutput() |
54 | 54 | { |
55 | - echo PHP_EOL.PHP_EOL; |
|
55 | + echo PHP_EOL . PHP_EOL; |
|
56 | 56 | |
57 | 57 | $output = 'The test files'; |
58 | - $data = []; |
|
58 | + $data = [ ]; |
|
59 | 59 | |
60 | - $codeCount = count($GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']); |
|
61 | - if (empty($GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']) === false) { |
|
62 | - $files = call_user_func_array('array_merge', $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']); |
|
63 | - $files = array_unique($files); |
|
64 | - $fileCount = count($files); |
|
60 | + $codeCount = count( $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CODES' ] ); |
|
61 | + if ( empty( $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CASE_FILES' ] ) === false ) { |
|
62 | + $files = call_user_func_array( 'array_merge', $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CASE_FILES' ] ); |
|
63 | + $files = array_unique( $files ); |
|
64 | + $fileCount = count( $files ); |
|
65 | 65 | |
66 | 66 | $output = '%d sniff test files'; |
67 | - $data[] = $fileCount; |
|
67 | + $data[ ] = $fileCount; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $output .= ' generated %d unique error codes'; |
71 | - $data[] = $codeCount; |
|
71 | + $data[ ] = $codeCount; |
|
72 | 72 | |
73 | - if ($codeCount > 0) { |
|
74 | - $fixes = count($GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']); |
|
75 | - $percent = round(($fixes / $codeCount * 100), 2); |
|
73 | + if ( $codeCount > 0 ) { |
|
74 | + $fixes = count( $GLOBALS[ 'PHP_CODESNIFFER_FIXABLE_CODES' ] ); |
|
75 | + $percent = round( ( $fixes / $codeCount * 100 ), 2 ); |
|
76 | 76 | |
77 | 77 | $output .= '; %d were fixable (%d%%)'; |
78 | - $data[] = $fixes; |
|
79 | - $data[] = $percent; |
|
78 | + $data[ ] = $fixes; |
|
79 | + $data[ ] = $percent; |
|
80 | 80 | } |
81 | 81 | |
82 | - vprintf($output, $data); |
|
82 | + vprintf( $output, $data ); |
|
83 | 83 | |
84 | 84 | }//end printPHPCodeSnifferTestOutput() |
@@ -50,8 +50,7 @@ |
||
50 | 50 | * |
51 | 51 | * @return void |
52 | 52 | */ |
53 | -function printPHPCodeSnifferTestOutput() |
|
54 | -{ |
|
53 | +function printPHPCodeSnifferTestOutput() { |
|
55 | 54 | echo PHP_EOL.PHP_EOL; |
56 | 55 | |
57 | 56 | $output = 'The test files'; |