@@ -36,7 +36,7 @@ |
||
36 | 36 | /** |
37 | 37 | * Returns an array of tokens this test wants to listen for. |
38 | 38 | * |
39 | - * @return array |
|
39 | + * @return string[] |
|
40 | 40 | */ |
41 | 41 | public function register() |
42 | 42 | { |
@@ -33,41 +33,41 @@ |
||
33 | 33 | class LogicalNotSpacingSniff implements Sniff |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * Returns an array of tokens this test wants to listen for. |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function register() |
|
42 | - { |
|
43 | - return array( |
|
44 | - T_BOOLEAN_NOT, |
|
45 | - ); |
|
46 | - }//end register() |
|
36 | + /** |
|
37 | + * Returns an array of tokens this test wants to listen for. |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function register() |
|
42 | + { |
|
43 | + return array( |
|
44 | + T_BOOLEAN_NOT, |
|
45 | + ); |
|
46 | + }//end register() |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Processes this test, when one of its tokens is encountered. |
|
51 | - * |
|
52 | - * @param File $phpcsFile The current file being scanned. |
|
53 | - * @param int $stackPtr The position of the current token |
|
54 | - * in the stack passed in $tokens. |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function process(File $phpcsFile, $stackPtr) |
|
59 | - { |
|
60 | - $tokens = $phpcsFile->getTokens(); |
|
49 | + /** |
|
50 | + * Processes this test, when one of its tokens is encountered. |
|
51 | + * |
|
52 | + * @param File $phpcsFile The current file being scanned. |
|
53 | + * @param int $stackPtr The position of the current token |
|
54 | + * in the stack passed in $tokens. |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function process(File $phpcsFile, $stackPtr) |
|
59 | + { |
|
60 | + $tokens = $phpcsFile->getTokens(); |
|
61 | 61 | |
62 | - $operator_token = $tokens[$stackPtr]; |
|
62 | + $operator_token = $tokens[$stackPtr]; |
|
63 | 63 | |
64 | - $previous_token = $tokens[$stackPtr - 1]; |
|
65 | - $next_token = $tokens[$stackPtr + 1]; |
|
66 | - if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) { |
|
67 | - $error = 'Logical operator ! should always be preceded and followed with a whitespace.'; |
|
68 | - $phpcsFile->addError($error, $stackPtr); |
|
69 | - } |
|
70 | - }//end process() |
|
64 | + $previous_token = $tokens[$stackPtr - 1]; |
|
65 | + $next_token = $tokens[$stackPtr + 1]; |
|
66 | + if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) { |
|
67 | + $error = 'Logical operator ! should always be preceded and followed with a whitespace.'; |
|
68 | + $phpcsFile->addError($error, $stackPtr); |
|
69 | + } |
|
70 | + }//end process() |
|
71 | 71 | |
72 | 72 | |
73 | 73 | }//end class |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | use PHP_CodeSniffer\Sniffs\Sniff; |
31 | 31 | use PHP_CodeSniffer\Files\File; |
32 | 32 | |
33 | -class LogicalNotSpacingSniff implements Sniff |
|
34 | -{ |
|
33 | +class LogicalNotSpacingSniff implements Sniff { |
|
35 | 34 | |
36 | 35 | /** |
37 | 36 | * Returns an array of tokens this test wants to listen for. |
@@ -63,7 +62,8 @@ discard block |
||
63 | 62 | |
64 | 63 | $previous_token = $tokens[$stackPtr - 1]; |
65 | 64 | $next_token = $tokens[$stackPtr + 1]; |
66 | - if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) { |
|
65 | + if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) |
|
66 | + { |
|
67 | 67 | $error = 'Logical operator ! should always be preceded and followed with a whitespace.'; |
68 | 68 | $phpcsFile->addError($error, $stackPtr); |
69 | 69 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | /** |
43 | 43 | * Returns an array of tokens this test wants to listen for. |
44 | 44 | * |
45 | - * @return array |
|
45 | + * @return integer[] |
|
46 | 46 | */ |
47 | 47 | public function register() |
48 | 48 | { |
@@ -39,71 +39,71 @@ |
||
39 | 39 | class ClosingFileCommentSniff extends AbstractClosingCommentSniff |
40 | 40 | { |
41 | 41 | |
42 | - /** |
|
43 | - * Returns an array of tokens this test wants to listen for. |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function register() |
|
48 | - { |
|
49 | - return array( |
|
50 | - T_OPEN_TAG, |
|
51 | - ); |
|
42 | + /** |
|
43 | + * Returns an array of tokens this test wants to listen for. |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function register() |
|
48 | + { |
|
49 | + return array( |
|
50 | + T_OPEN_TAG, |
|
51 | + ); |
|
52 | 52 | |
53 | - }//end register() |
|
53 | + }//end register() |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Processes this test, when one of its tokens is encountered. |
|
58 | - * |
|
59 | - * @param File $phpcsFile The current file being scanned. |
|
60 | - * @param int $stackPtr The position of the current token |
|
61 | - * in the stack passed in $tokens. |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | - { |
|
67 | - // We are only interested if this is the first open tag. |
|
68 | - if ($stackPtr !== 0) { |
|
69 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
70 | - return; |
|
71 | - } |
|
72 | - } |
|
56 | + /** |
|
57 | + * Processes this test, when one of its tokens is encountered. |
|
58 | + * |
|
59 | + * @param File $phpcsFile The current file being scanned. |
|
60 | + * @param int $stackPtr The position of the current token |
|
61 | + * in the stack passed in $tokens. |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function process(File $phpcsFile, $stackPtr) |
|
66 | + { |
|
67 | + // We are only interested if this is the first open tag. |
|
68 | + if ($stackPtr !== 0) { |
|
69 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
70 | + return; |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - $fullFilename = $phpcsFile->getFilename(); |
|
75 | - $filename = basename($fullFilename); |
|
76 | - $commentTemplate = "End of file $filename"; |
|
74 | + $fullFilename = $phpcsFile->getFilename(); |
|
75 | + $filename = basename($fullFilename); |
|
76 | + $commentTemplate = "End of file $filename"; |
|
77 | 77 | |
78 | - $tokens = $phpcsFile->getTokens(); |
|
79 | - $currentToken = count($tokens) - 1; |
|
80 | - $hasClosingFileComment = false; |
|
81 | - $isNotAWhitespaceOrAComment = false; |
|
82 | - while ($currentToken >= 0 |
|
83 | - && ! $isNotAWhitespaceOrAComment |
|
84 | - && ! $hasClosingFileComment |
|
85 | - ) { |
|
86 | - $token = $tokens[$currentToken]; |
|
87 | - $tokenCode = $token['code']; |
|
88 | - if (T_COMMENT === $tokenCode) { |
|
89 | - $commentString = self::_getCommentContent($token['content']); |
|
90 | - if (0 === strcmp($commentString, $commentTemplate)) { |
|
91 | - $hasClosingFileComment = true; |
|
92 | - } |
|
93 | - } else if (T_WHITESPACE === $tokenCode) { |
|
94 | - // Whitespaces are allowed between the closing file comment, |
|
95 | - // other comments and end of file |
|
96 | - } else { |
|
97 | - $isNotAWhitespaceOrAComment = true; |
|
98 | - } |
|
99 | - $currentToken--; |
|
100 | - } |
|
78 | + $tokens = $phpcsFile->getTokens(); |
|
79 | + $currentToken = count($tokens) - 1; |
|
80 | + $hasClosingFileComment = false; |
|
81 | + $isNotAWhitespaceOrAComment = false; |
|
82 | + while ($currentToken >= 0 |
|
83 | + && ! $isNotAWhitespaceOrAComment |
|
84 | + && ! $hasClosingFileComment |
|
85 | + ) { |
|
86 | + $token = $tokens[$currentToken]; |
|
87 | + $tokenCode = $token['code']; |
|
88 | + if (T_COMMENT === $tokenCode) { |
|
89 | + $commentString = self::_getCommentContent($token['content']); |
|
90 | + if (0 === strcmp($commentString, $commentTemplate)) { |
|
91 | + $hasClosingFileComment = true; |
|
92 | + } |
|
93 | + } else if (T_WHITESPACE === $tokenCode) { |
|
94 | + // Whitespaces are allowed between the closing file comment, |
|
95 | + // other comments and end of file |
|
96 | + } else { |
|
97 | + $isNotAWhitespaceOrAComment = true; |
|
98 | + } |
|
99 | + $currentToken--; |
|
100 | + } |
|
101 | 101 | |
102 | - if ( ! $hasClosingFileComment) { |
|
103 | - $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
|
104 | - $phpcsFile->addError($error, $currentToken); |
|
105 | - } |
|
106 | - }//end process() |
|
102 | + if ( ! $hasClosingFileComment) { |
|
103 | + $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
|
104 | + $phpcsFile->addError($error, $currentToken); |
|
105 | + } |
|
106 | + }//end process() |
|
107 | 107 | }//end class |
108 | 108 | |
109 | 109 | ?> |
@@ -36,8 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | use PHP_CodeSniffer\Files\File; |
38 | 38 | |
39 | -class ClosingFileCommentSniff extends AbstractClosingCommentSniff |
|
40 | -{ |
|
39 | +class ClosingFileCommentSniff extends AbstractClosingCommentSniff { |
|
41 | 40 | |
42 | 41 | /** |
43 | 42 | * Returns an array of tokens this test wants to listen for. |
@@ -65,8 +64,10 @@ discard block |
||
65 | 64 | public function process(File $phpcsFile, $stackPtr) |
66 | 65 | { |
67 | 66 | // We are only interested if this is the first open tag. |
68 | - if ($stackPtr !== 0) { |
|
69 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
67 | + if ($stackPtr !== 0) |
|
68 | + { |
|
69 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) |
|
70 | + { |
|
70 | 71 | return; |
71 | 72 | } |
72 | 73 | } |
@@ -85,21 +86,28 @@ discard block |
||
85 | 86 | ) { |
86 | 87 | $token = $tokens[$currentToken]; |
87 | 88 | $tokenCode = $token['code']; |
88 | - if (T_COMMENT === $tokenCode) { |
|
89 | + if (T_COMMENT === $tokenCode) |
|
90 | + { |
|
89 | 91 | $commentString = self::_getCommentContent($token['content']); |
90 | - if (0 === strcmp($commentString, $commentTemplate)) { |
|
92 | + if (0 === strcmp($commentString, $commentTemplate)) |
|
93 | + { |
|
91 | 94 | $hasClosingFileComment = true; |
92 | 95 | } |
93 | - } else if (T_WHITESPACE === $tokenCode) { |
|
96 | + } |
|
97 | + else if (T_WHITESPACE === $tokenCode) |
|
98 | + { |
|
94 | 99 | // Whitespaces are allowed between the closing file comment, |
95 | 100 | // other comments and end of file |
96 | - } else { |
|
101 | + } |
|
102 | + else |
|
103 | + { |
|
97 | 104 | $isNotAWhitespaceOrAComment = true; |
98 | 105 | } |
99 | 106 | $currentToken--; |
100 | 107 | } |
101 | 108 | |
102 | - if ( ! $hasClosingFileComment) { |
|
109 | + if ( ! $hasClosingFileComment) |
|
110 | + { |
|
103 | 111 | $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
104 | 112 | $phpcsFile->addError($error, $currentToken); |
105 | 113 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | { |
67 | 67 | // We are only interested if this is the first open tag. |
68 | 68 | if ($stackPtr !== 0) { |
69 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
69 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== FALSE) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | } |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | |
78 | 78 | $tokens = $phpcsFile->getTokens(); |
79 | 79 | $currentToken = count($tokens) - 1; |
80 | - $hasClosingFileComment = false; |
|
81 | - $isNotAWhitespaceOrAComment = false; |
|
80 | + $hasClosingFileComment = FALSE; |
|
81 | + $isNotAWhitespaceOrAComment = FALSE; |
|
82 | 82 | while ($currentToken >= 0 |
83 | 83 | && ! $isNotAWhitespaceOrAComment |
84 | 84 | && ! $hasClosingFileComment |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | if (T_COMMENT === $tokenCode) { |
89 | 89 | $commentString = self::_getCommentContent($token['content']); |
90 | 90 | if (0 === strcmp($commentString, $commentTemplate)) { |
91 | - $hasClosingFileComment = true; |
|
91 | + $hasClosingFileComment = TRUE; |
|
92 | 92 | } |
93 | 93 | } else if (T_WHITESPACE === $tokenCode) { |
94 | 94 | // Whitespaces are allowed between the closing file comment, |
95 | 95 | // other comments and end of file |
96 | 96 | } else { |
97 | - $isNotAWhitespaceOrAComment = true; |
|
97 | + $isNotAWhitespaceOrAComment = TRUE; |
|
98 | 98 | } |
99 | 99 | $currentToken--; |
100 | 100 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Returns an array of tokens this test wants to listen for. |
52 | 52 | * |
53 | - * @return array |
|
53 | + * @return integer[] |
|
54 | 54 | */ |
55 | 55 | public function register() |
56 | 56 | { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * application root. Parent directory of the application root are allowed |
135 | 135 | * but not mandatory. |
136 | 136 | * |
137 | - * @return string|bool The relative path from $appRoot to $filePath, or |
|
137 | + * @return false|string The relative path from $appRoot to $filePath, or |
|
138 | 138 | * false if $appRoot cannot be found in $filePath. |
139 | 139 | */ |
140 | 140 | private static function _getLocationPath ($filePath, $appRoot) |
@@ -45,138 +45,138 @@ |
||
45 | 45 | |
46 | 46 | class ClosingLocationCommentSniff extends AbstractClosingCommentSniff |
47 | 47 | { |
48 | - public $applicationRoot = '/application/'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Returns an array of tokens this test wants to listen for. |
|
52 | - * |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function register() |
|
56 | - { |
|
57 | - return array( |
|
58 | - T_OPEN_TAG |
|
59 | - ); |
|
60 | - |
|
61 | - }//end register() |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Processes this test, when one of its tokens is encountered. |
|
66 | - * |
|
67 | - * @param File $phpcsFile The current file being scanned. |
|
68 | - * @param int $stackPtr The position of the current token |
|
69 | - * in the stack passed in $tokens. |
|
70 | - * |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function process(File $phpcsFile, $stackPtr) |
|
74 | - { |
|
75 | - // We are only interested if this is the first open tag. |
|
76 | - if ($stackPtr !== 0) { |
|
77 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
78 | - return; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - $filePath = $phpcsFile->getFilename(); |
|
83 | - $tokens = $phpcsFile->getTokens(); |
|
84 | - // removes the application root from the beginning of the file path |
|
85 | - $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot()); |
|
86 | - // add an error, if application root doesn't exist in current file path |
|
87 | - if (false === $locationPath) { |
|
88 | - $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.'; |
|
89 | - $phpcsFile->addError($error, count($tokens) - 1); |
|
90 | - return; |
|
91 | - } |
|
92 | - // generates the expected comment |
|
93 | - $commentTemplate = "Location: $locationPath"; |
|
94 | - |
|
95 | - $currentToken = count($tokens) - 1; |
|
96 | - $hasClosingLocationComment = false; |
|
97 | - $isNotAWhitespaceOrAComment = false; |
|
98 | - while ($currentToken >= 0 |
|
99 | - && ! $isNotAWhitespaceOrAComment |
|
100 | - && ! $hasClosingLocationComment |
|
101 | - ) { |
|
102 | - $token = $tokens[$currentToken]; |
|
103 | - $tokenCode = $token['code']; |
|
104 | - if (T_COMMENT === $tokenCode) { |
|
105 | - $commentString = self::_getCommentContent($token['content']); |
|
106 | - if (0 === strcmp($commentString, $commentTemplate)) { |
|
107 | - $hasClosingLocationComment = true; |
|
108 | - } |
|
109 | - } else if (T_WHITESPACE === $tokenCode) { |
|
110 | - // Whitespaces are allowed between the closing file comment, |
|
111 | - //other comments and end of file |
|
112 | - } else { |
|
113 | - $isNotAWhitespaceOrAComment = true; |
|
114 | - } |
|
115 | - $currentToken--; |
|
116 | - } |
|
117 | - |
|
118 | - if ( ! $hasClosingLocationComment) { |
|
119 | - $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
|
120 | - $phpcsFile->addError($error, $currentToken); |
|
121 | - } |
|
122 | - }//end process() |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns the relative path from $appRoot to $filePath, or false if |
|
127 | - * $appRoot cannot be found in $filePath, because $appRoot is not a parent |
|
128 | - * of $filePath. |
|
129 | - * |
|
130 | - * @param string $filePath Full path to the file being proceed. |
|
131 | - * @param string $appRoot Partial or full path to the CodeIgniter |
|
132 | - * application root of the file being proceed. It must not contain the |
|
133 | - * full path to the application root, but at least the name of the |
|
134 | - * application root. Parent directory of the application root are allowed |
|
135 | - * but not mandatory. |
|
136 | - * |
|
137 | - * @return string|bool The relative path from $appRoot to $filePath, or |
|
138 | - * false if $appRoot cannot be found in $filePath. |
|
139 | - */ |
|
140 | - private static function _getLocationPath ($filePath, $appRoot) |
|
141 | - { |
|
142 | - // removes the path to application root |
|
143 | - // from the beginning of the file path |
|
144 | - $appRootAt = strpos($filePath, $appRoot); |
|
145 | - if (false === $appRootAt) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - $localPath = substr($filePath, $appRootAt + strlen($appRoot)); |
|
149 | - // ensures the location path to be a relative path starting with "./". |
|
150 | - if ( ! self::_stringStartsWith($localPath, './')) { |
|
151 | - $localPath = './' . $localPath; |
|
152 | - } else if ( ! self::_stringStartsWith($localPath, '.') |
|
153 | - && self::_stringStartsWith($localPath, '/') |
|
154 | - ) { |
|
155 | - $localPath = '.' . $localPath; |
|
156 | - } |
|
157 | - return $localPath; |
|
158 | - }//end _getLocationPath() |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Returns the application root that should be used first. |
|
163 | - * |
|
164 | - * There are several ways to configure the application root. |
|
165 | - * In order of priority : |
|
166 | - * - Configuration variable ci_application_root. |
|
167 | - * - Rule property applicationRoot. |
|
168 | - * - Default value '/application/' |
|
169 | - * |
|
170 | - * @return string Path to your project application root. |
|
171 | - */ |
|
172 | - private function _getAppRoot() |
|
173 | - { |
|
174 | - $appRoot = Common::getConfigData('ci_application_root'); |
|
175 | - if (null === $appRoot) { |
|
176 | - $appRoot = $this->applicationRoot; |
|
177 | - } |
|
178 | - return $appRoot; |
|
179 | - }//end _getAppRoot() |
|
48 | + public $applicationRoot = '/application/'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Returns an array of tokens this test wants to listen for. |
|
52 | + * |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function register() |
|
56 | + { |
|
57 | + return array( |
|
58 | + T_OPEN_TAG |
|
59 | + ); |
|
60 | + |
|
61 | + }//end register() |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Processes this test, when one of its tokens is encountered. |
|
66 | + * |
|
67 | + * @param File $phpcsFile The current file being scanned. |
|
68 | + * @param int $stackPtr The position of the current token |
|
69 | + * in the stack passed in $tokens. |
|
70 | + * |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function process(File $phpcsFile, $stackPtr) |
|
74 | + { |
|
75 | + // We are only interested if this is the first open tag. |
|
76 | + if ($stackPtr !== 0) { |
|
77 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
78 | + return; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + $filePath = $phpcsFile->getFilename(); |
|
83 | + $tokens = $phpcsFile->getTokens(); |
|
84 | + // removes the application root from the beginning of the file path |
|
85 | + $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot()); |
|
86 | + // add an error, if application root doesn't exist in current file path |
|
87 | + if (false === $locationPath) { |
|
88 | + $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.'; |
|
89 | + $phpcsFile->addError($error, count($tokens) - 1); |
|
90 | + return; |
|
91 | + } |
|
92 | + // generates the expected comment |
|
93 | + $commentTemplate = "Location: $locationPath"; |
|
94 | + |
|
95 | + $currentToken = count($tokens) - 1; |
|
96 | + $hasClosingLocationComment = false; |
|
97 | + $isNotAWhitespaceOrAComment = false; |
|
98 | + while ($currentToken >= 0 |
|
99 | + && ! $isNotAWhitespaceOrAComment |
|
100 | + && ! $hasClosingLocationComment |
|
101 | + ) { |
|
102 | + $token = $tokens[$currentToken]; |
|
103 | + $tokenCode = $token['code']; |
|
104 | + if (T_COMMENT === $tokenCode) { |
|
105 | + $commentString = self::_getCommentContent($token['content']); |
|
106 | + if (0 === strcmp($commentString, $commentTemplate)) { |
|
107 | + $hasClosingLocationComment = true; |
|
108 | + } |
|
109 | + } else if (T_WHITESPACE === $tokenCode) { |
|
110 | + // Whitespaces are allowed between the closing file comment, |
|
111 | + //other comments and end of file |
|
112 | + } else { |
|
113 | + $isNotAWhitespaceOrAComment = true; |
|
114 | + } |
|
115 | + $currentToken--; |
|
116 | + } |
|
117 | + |
|
118 | + if ( ! $hasClosingLocationComment) { |
|
119 | + $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
|
120 | + $phpcsFile->addError($error, $currentToken); |
|
121 | + } |
|
122 | + }//end process() |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns the relative path from $appRoot to $filePath, or false if |
|
127 | + * $appRoot cannot be found in $filePath, because $appRoot is not a parent |
|
128 | + * of $filePath. |
|
129 | + * |
|
130 | + * @param string $filePath Full path to the file being proceed. |
|
131 | + * @param string $appRoot Partial or full path to the CodeIgniter |
|
132 | + * application root of the file being proceed. It must not contain the |
|
133 | + * full path to the application root, but at least the name of the |
|
134 | + * application root. Parent directory of the application root are allowed |
|
135 | + * but not mandatory. |
|
136 | + * |
|
137 | + * @return string|bool The relative path from $appRoot to $filePath, or |
|
138 | + * false if $appRoot cannot be found in $filePath. |
|
139 | + */ |
|
140 | + private static function _getLocationPath ($filePath, $appRoot) |
|
141 | + { |
|
142 | + // removes the path to application root |
|
143 | + // from the beginning of the file path |
|
144 | + $appRootAt = strpos($filePath, $appRoot); |
|
145 | + if (false === $appRootAt) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + $localPath = substr($filePath, $appRootAt + strlen($appRoot)); |
|
149 | + // ensures the location path to be a relative path starting with "./". |
|
150 | + if ( ! self::_stringStartsWith($localPath, './')) { |
|
151 | + $localPath = './' . $localPath; |
|
152 | + } else if ( ! self::_stringStartsWith($localPath, '.') |
|
153 | + && self::_stringStartsWith($localPath, '/') |
|
154 | + ) { |
|
155 | + $localPath = '.' . $localPath; |
|
156 | + } |
|
157 | + return $localPath; |
|
158 | + }//end _getLocationPath() |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Returns the application root that should be used first. |
|
163 | + * |
|
164 | + * There are several ways to configure the application root. |
|
165 | + * In order of priority : |
|
166 | + * - Configuration variable ci_application_root. |
|
167 | + * - Rule property applicationRoot. |
|
168 | + * - Default value '/application/' |
|
169 | + * |
|
170 | + * @return string Path to your project application root. |
|
171 | + */ |
|
172 | + private function _getAppRoot() |
|
173 | + { |
|
174 | + $appRoot = Common::getConfigData('ci_application_root'); |
|
175 | + if (null === $appRoot) { |
|
176 | + $appRoot = $this->applicationRoot; |
|
177 | + } |
|
178 | + return $appRoot; |
|
179 | + }//end _getAppRoot() |
|
180 | 180 | }//end class |
181 | 181 | |
182 | 182 | ?> |
@@ -137,7 +137,7 @@ |
||
137 | 137 | * @return string|bool The relative path from $appRoot to $filePath, or |
138 | 138 | * false if $appRoot cannot be found in $filePath. |
139 | 139 | */ |
140 | - private static function _getLocationPath ($filePath, $appRoot) |
|
140 | + private static function _getLocationPath($filePath, $appRoot) |
|
141 | 141 | { |
142 | 142 | // removes the path to application root |
143 | 143 | // from the beginning of the file path |
@@ -43,8 +43,7 @@ discard block |
||
43 | 43 | use PHP_CodeSniffer\Files\File; |
44 | 44 | use PHP_CodeSniffer\Util\Common; |
45 | 45 | |
46 | -class ClosingLocationCommentSniff extends AbstractClosingCommentSniff |
|
47 | -{ |
|
46 | +class ClosingLocationCommentSniff extends AbstractClosingCommentSniff { |
|
48 | 47 | public $applicationRoot = '/application/'; |
49 | 48 | |
50 | 49 | /** |
@@ -73,8 +72,10 @@ discard block |
||
73 | 72 | public function process(File $phpcsFile, $stackPtr) |
74 | 73 | { |
75 | 74 | // We are only interested if this is the first open tag. |
76 | - if ($stackPtr !== 0) { |
|
77 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
75 | + if ($stackPtr !== 0) |
|
76 | + { |
|
77 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) |
|
78 | + { |
|
78 | 79 | return; |
79 | 80 | } |
80 | 81 | } |
@@ -84,7 +85,8 @@ discard block |
||
84 | 85 | // removes the application root from the beginning of the file path |
85 | 86 | $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot()); |
86 | 87 | // add an error, if application root doesn't exist in current file path |
87 | - if (false === $locationPath) { |
|
88 | + if (false === $locationPath) |
|
89 | + { |
|
88 | 90 | $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.'; |
89 | 91 | $phpcsFile->addError($error, count($tokens) - 1); |
90 | 92 | return; |
@@ -101,21 +103,28 @@ discard block |
||
101 | 103 | ) { |
102 | 104 | $token = $tokens[$currentToken]; |
103 | 105 | $tokenCode = $token['code']; |
104 | - if (T_COMMENT === $tokenCode) { |
|
106 | + if (T_COMMENT === $tokenCode) |
|
107 | + { |
|
105 | 108 | $commentString = self::_getCommentContent($token['content']); |
106 | - if (0 === strcmp($commentString, $commentTemplate)) { |
|
109 | + if (0 === strcmp($commentString, $commentTemplate)) |
|
110 | + { |
|
107 | 111 | $hasClosingLocationComment = true; |
108 | 112 | } |
109 | - } else if (T_WHITESPACE === $tokenCode) { |
|
113 | + } |
|
114 | + else if (T_WHITESPACE === $tokenCode) |
|
115 | + { |
|
110 | 116 | // Whitespaces are allowed between the closing file comment, |
111 | 117 | //other comments and end of file |
112 | - } else { |
|
118 | + } |
|
119 | + else |
|
120 | + { |
|
113 | 121 | $isNotAWhitespaceOrAComment = true; |
114 | 122 | } |
115 | 123 | $currentToken--; |
116 | 124 | } |
117 | 125 | |
118 | - if ( ! $hasClosingLocationComment) { |
|
126 | + if ( ! $hasClosingLocationComment) |
|
127 | + { |
|
119 | 128 | $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
120 | 129 | $phpcsFile->addError($error, $currentToken); |
121 | 130 | } |
@@ -142,14 +151,17 @@ discard block |
||
142 | 151 | // removes the path to application root |
143 | 152 | // from the beginning of the file path |
144 | 153 | $appRootAt = strpos($filePath, $appRoot); |
145 | - if (false === $appRootAt) { |
|
154 | + if (false === $appRootAt) |
|
155 | + { |
|
146 | 156 | return false; |
147 | 157 | } |
148 | 158 | $localPath = substr($filePath, $appRootAt + strlen($appRoot)); |
149 | 159 | // ensures the location path to be a relative path starting with "./". |
150 | - if ( ! self::_stringStartsWith($localPath, './')) { |
|
160 | + if ( ! self::_stringStartsWith($localPath, './')) |
|
161 | + { |
|
151 | 162 | $localPath = './' . $localPath; |
152 | - } else if ( ! self::_stringStartsWith($localPath, '.') |
|
163 | + } |
|
164 | + else if ( ! self::_stringStartsWith($localPath, '.') |
|
153 | 165 | && self::_stringStartsWith($localPath, '/') |
154 | 166 | ) { |
155 | 167 | $localPath = '.' . $localPath; |
@@ -172,7 +184,8 @@ discard block |
||
172 | 184 | private function _getAppRoot() |
173 | 185 | { |
174 | 186 | $appRoot = Common::getConfigData('ci_application_root'); |
175 | - if (null === $appRoot) { |
|
187 | + if (null === $appRoot) |
|
188 | + { |
|
176 | 189 | $appRoot = $this->applicationRoot; |
177 | 190 | } |
178 | 191 | return $appRoot; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | { |
75 | 75 | // We are only interested if this is the first open tag. |
76 | 76 | if ($stackPtr !== 0) { |
77 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
77 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== FALSE) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | // removes the application root from the beginning of the file path |
85 | 85 | $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot()); |
86 | 86 | // add an error, if application root doesn't exist in current file path |
87 | - if (false === $locationPath) { |
|
87 | + if (FALSE === $locationPath) { |
|
88 | 88 | $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.'; |
89 | 89 | $phpcsFile->addError($error, count($tokens) - 1); |
90 | 90 | return; |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | $commentTemplate = "Location: $locationPath"; |
94 | 94 | |
95 | 95 | $currentToken = count($tokens) - 1; |
96 | - $hasClosingLocationComment = false; |
|
97 | - $isNotAWhitespaceOrAComment = false; |
|
96 | + $hasClosingLocationComment = FALSE; |
|
97 | + $isNotAWhitespaceOrAComment = FALSE; |
|
98 | 98 | while ($currentToken >= 0 |
99 | 99 | && ! $isNotAWhitespaceOrAComment |
100 | 100 | && ! $hasClosingLocationComment |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | if (T_COMMENT === $tokenCode) { |
105 | 105 | $commentString = self::_getCommentContent($token['content']); |
106 | 106 | if (0 === strcmp($commentString, $commentTemplate)) { |
107 | - $hasClosingLocationComment = true; |
|
107 | + $hasClosingLocationComment = TRUE; |
|
108 | 108 | } |
109 | 109 | } else if (T_WHITESPACE === $tokenCode) { |
110 | 110 | // Whitespaces are allowed between the closing file comment, |
111 | 111 | //other comments and end of file |
112 | 112 | } else { |
113 | - $isNotAWhitespaceOrAComment = true; |
|
113 | + $isNotAWhitespaceOrAComment = TRUE; |
|
114 | 114 | } |
115 | 115 | $currentToken--; |
116 | 116 | } |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | // removes the path to application root |
143 | 143 | // from the beginning of the file path |
144 | 144 | $appRootAt = strpos($filePath, $appRoot); |
145 | - if (false === $appRootAt) { |
|
146 | - return false; |
|
145 | + if (FALSE === $appRootAt) { |
|
146 | + return FALSE; |
|
147 | 147 | } |
148 | 148 | $localPath = substr($filePath, $appRootAt + strlen($appRoot)); |
149 | 149 | // ensures the location path to be a relative path starting with "./". |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | private function _getAppRoot() |
173 | 173 | { |
174 | 174 | $appRoot = Common::getConfigData('ci_application_root'); |
175 | - if (null === $appRoot) { |
|
175 | + if (NULL === $appRoot) { |
|
176 | 176 | $appRoot = $this->applicationRoot; |
177 | 177 | } |
178 | 178 | return $appRoot; |
@@ -42,7 +42,7 @@ |
||
42 | 42 | /** |
43 | 43 | * Returns an array of tokens this test wants to listen for. |
44 | 44 | * |
45 | - * @return array |
|
45 | + * @return integer[] |
|
46 | 46 | */ |
47 | 47 | public function register() |
48 | 48 | { |
@@ -39,45 +39,45 @@ |
||
39 | 39 | { |
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Returns an array of tokens this test wants to listen for. |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function register() |
|
48 | - { |
|
49 | - return array( |
|
50 | - T_CLASS, |
|
51 | - T_INTERFACE, |
|
52 | - ); |
|
42 | + /** |
|
43 | + * Returns an array of tokens this test wants to listen for. |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function register() |
|
48 | + { |
|
49 | + return array( |
|
50 | + T_CLASS, |
|
51 | + T_INTERFACE, |
|
52 | + ); |
|
53 | 53 | |
54 | - }//end register() |
|
54 | + }//end register() |
|
55 | 55 | |
56 | - /** |
|
57 | - * Processes this test, when one of its tokens is encountered. |
|
58 | - * |
|
59 | - * @param File $phpcsFile The current file being processed. |
|
60 | - * @param int $stackPtr The position of the current token |
|
61 | - * in the stack passed in $tokens. |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | - { |
|
67 | - // get the class name |
|
68 | - $className = trim($phpcsFile->getDeclarationName($stackPtr)); |
|
69 | - // compute the expected class name |
|
70 | - // [^_] means "something different from _", but not "nothing or something different from _" |
|
71 | - $lcClassNameChunk = preg_replace('/([^_])([A-Z])/', '${1}_${2}', $className); |
|
72 | - $expectedClassName |
|
73 | - = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1)); |
|
74 | - // ensures that the current class name |
|
75 | - // and the expected class name are identical |
|
76 | - if (0 !== strcmp($className, $expectedClassName)) { |
|
77 | - $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
|
78 | - $phpcsFile->addError($error, $stackPtr); |
|
79 | - } |
|
80 | - }//end process() |
|
56 | + /** |
|
57 | + * Processes this test, when one of its tokens is encountered. |
|
58 | + * |
|
59 | + * @param File $phpcsFile The current file being processed. |
|
60 | + * @param int $stackPtr The position of the current token |
|
61 | + * in the stack passed in $tokens. |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function process(File $phpcsFile, $stackPtr) |
|
66 | + { |
|
67 | + // get the class name |
|
68 | + $className = trim($phpcsFile->getDeclarationName($stackPtr)); |
|
69 | + // compute the expected class name |
|
70 | + // [^_] means "something different from _", but not "nothing or something different from _" |
|
71 | + $lcClassNameChunk = preg_replace('/([^_])([A-Z])/', '${1}_${2}', $className); |
|
72 | + $expectedClassName |
|
73 | + = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1)); |
|
74 | + // ensures that the current class name |
|
75 | + // and the expected class name are identical |
|
76 | + if (0 !== strcmp($className, $expectedClassName)) { |
|
77 | + $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
|
78 | + $phpcsFile->addError($error, $stackPtr); |
|
79 | + } |
|
80 | + }//end process() |
|
81 | 81 | |
82 | 82 | }//end class |
83 | 83 |
@@ -70,11 +70,11 @@ |
||
70 | 70 | // [^_] means "something different from _", but not "nothing or something different from _" |
71 | 71 | $lcClassNameChunk = preg_replace('/([^_])([A-Z])/', '${1}_${2}', $className); |
72 | 72 | $expectedClassName |
73 | - = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1)); |
|
73 | + = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk, 1)); |
|
74 | 74 | // ensures that the current class name |
75 | 75 | // and the expected class name are identical |
76 | 76 | if (0 !== strcmp($className, $expectedClassName)) { |
77 | - $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
|
77 | + $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
|
78 | 78 | $phpcsFile->addError($error, $stackPtr); |
79 | 79 | } |
80 | 80 | }//end process() |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | use PHP_CodeSniffer\Sniffs\Sniff; |
36 | 36 | use PHP_CodeSniffer\Files\File; |
37 | 37 | |
38 | -class ValidClassNameSniff implements Sniff |
|
39 | -{ |
|
38 | +class ValidClassNameSniff implements Sniff { |
|
40 | 39 | |
41 | 40 | |
42 | 41 | /** |
@@ -73,7 +72,8 @@ discard block |
||
73 | 72 | = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1)); |
74 | 73 | // ensures that the current class name |
75 | 74 | // and the expected class name are identical |
76 | - if (0 !== strcmp($className, $expectedClassName)) { |
|
75 | + if (0 !== strcmp($className, $expectedClassName)) |
|
76 | + { |
|
77 | 77 | $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
78 | 78 | $phpcsFile->addError($error, $stackPtr); |
79 | 79 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | /** |
36 | 36 | * Returns an array of tokens this test wants to listen for. |
37 | 37 | * |
38 | - * @return array |
|
38 | + * @return integer[] |
|
39 | 39 | */ |
40 | 40 | public function register() |
41 | 41 | { |
@@ -32,53 +32,53 @@ |
||
32 | 32 | |
33 | 33 | class ValidFileNameSniff implements Sniff |
34 | 34 | { |
35 | - /** |
|
36 | - * Returns an array of tokens this test wants to listen for. |
|
37 | - * |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function register() |
|
41 | - { |
|
42 | - return array( |
|
43 | - T_CLASS, |
|
44 | - T_INTERFACE, |
|
45 | - ); |
|
46 | - }//end register() |
|
35 | + /** |
|
36 | + * Returns an array of tokens this test wants to listen for. |
|
37 | + * |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function register() |
|
41 | + { |
|
42 | + return array( |
|
43 | + T_CLASS, |
|
44 | + T_INTERFACE, |
|
45 | + ); |
|
46 | + }//end register() |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Processes this test, when one of its tokens is encountered. |
|
51 | - * |
|
52 | - * @param File $phpcsFile The file being scanned. |
|
53 | - * @param int $stackPtr The position of the current token in the |
|
54 | - * stack passed in $tokens. |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function process(File $phpcsFile, $stackPtr) |
|
59 | - { |
|
60 | - $tokens = $phpcsFile->getTokens(); |
|
61 | - // computes the expected filename based on the name of the class or interface that it contains. |
|
62 | - $decNamePtr = $phpcsFile->findNext(T_STRING, $stackPtr); |
|
63 | - $decName = $tokens[$decNamePtr]['content']; |
|
64 | - $expectedFileName = strtolower($decName); |
|
65 | - // extracts filename without extension from its path. |
|
66 | - $fullPath = $phpcsFile->getFilename(); |
|
67 | - $fileNameAndExt = basename($fullPath); |
|
68 | - $fileName = substr($fileNameAndExt, 0, strrpos($fileNameAndExt, '.')); |
|
49 | + /** |
|
50 | + * Processes this test, when one of its tokens is encountered. |
|
51 | + * |
|
52 | + * @param File $phpcsFile The file being scanned. |
|
53 | + * @param int $stackPtr The position of the current token in the |
|
54 | + * stack passed in $tokens. |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function process(File $phpcsFile, $stackPtr) |
|
59 | + { |
|
60 | + $tokens = $phpcsFile->getTokens(); |
|
61 | + // computes the expected filename based on the name of the class or interface that it contains. |
|
62 | + $decNamePtr = $phpcsFile->findNext(T_STRING, $stackPtr); |
|
63 | + $decName = $tokens[$decNamePtr]['content']; |
|
64 | + $expectedFileName = strtolower($decName); |
|
65 | + // extracts filename without extension from its path. |
|
66 | + $fullPath = $phpcsFile->getFilename(); |
|
67 | + $fileNameAndExt = basename($fullPath); |
|
68 | + $fileName = substr($fileNameAndExt, 0, strrpos($fileNameAndExt, '.')); |
|
69 | 69 | |
70 | - if ($expectedFileName !== $fileName) { |
|
71 | - $errorTemplate = 'Filename "%s" doesn\'t match the name of the %s that it contains "%s" in lower case. "%s" was expected.'; |
|
72 | - $errorMessage = sprintf( |
|
73 | - $errorTemplate, |
|
74 | - $fileName, |
|
75 | - strtolower($tokens[$stackPtr]['content']), // class or interface |
|
76 | - $decName, |
|
77 | - $expectedFileName |
|
78 | - ); |
|
79 | - $phpcsFile->addError($errorMessage, 0); |
|
80 | - } |
|
81 | - }//end process() |
|
70 | + if ($expectedFileName !== $fileName) { |
|
71 | + $errorTemplate = 'Filename "%s" doesn\'t match the name of the %s that it contains "%s" in lower case. "%s" was expected.'; |
|
72 | + $errorMessage = sprintf( |
|
73 | + $errorTemplate, |
|
74 | + $fileName, |
|
75 | + strtolower($tokens[$stackPtr]['content']), // class or interface |
|
76 | + $decName, |
|
77 | + $expectedFileName |
|
78 | + ); |
|
79 | + $phpcsFile->addError($errorMessage, 0); |
|
80 | + } |
|
81 | + }//end process() |
|
82 | 82 | }//end class |
83 | 83 | |
84 | 84 | ?> |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | use PHP_CodeSniffer\Sniffs\Sniff; |
31 | 31 | use PHP_CodeSniffer\Files\File; |
32 | 32 | |
33 | -class ValidFileNameSniff implements Sniff |
|
34 | -{ |
|
33 | +class ValidFileNameSniff implements Sniff { |
|
35 | 34 | /** |
36 | 35 | * Returns an array of tokens this test wants to listen for. |
37 | 36 | * |
@@ -67,7 +66,8 @@ discard block |
||
67 | 66 | $fileNameAndExt = basename($fullPath); |
68 | 67 | $fileName = substr($fileNameAndExt, 0, strrpos($fileNameAndExt, '.')); |
69 | 68 | |
70 | - if ($expectedFileName !== $fileName) { |
|
69 | + if ($expectedFileName !== $fileName) |
|
70 | + { |
|
71 | 71 | $errorTemplate = 'Filename "%s" doesn\'t match the name of the %s that it contains "%s" in lower case. "%s" was expected.'; |
72 | 72 | $errorMessage = sprintf( |
73 | 73 | $errorTemplate, |
@@ -2,6 +2,10 @@ discard block |
||
2 | 2 | if ( ! function_exists('glob_recursive')) |
3 | 3 | { |
4 | 4 | // Does not support flag GLOB_BRACE |
5 | + |
|
6 | + /** |
|
7 | + * @param string $pattern |
|
8 | + */ |
|
5 | 9 | function glob_recursive($pattern, $flags = 0) |
6 | 10 | { |
7 | 11 | $files = glob($pattern, $flags); |
@@ -320,7 +324,7 @@ discard block |
||
320 | 324 | * Shortcut for joining an array of command arguments |
321 | 325 | * and then running it |
322 | 326 | * |
323 | - * @param array $cmd_parts - command arguments |
|
327 | + * @param string[] $cmd_parts - command arguments |
|
324 | 328 | * @param string $join_on - what to join the command arguments with |
325 | 329 | */ |
326 | 330 | protected function _run(array $cmd_parts, $join_on = ' ') |
@@ -6,9 +6,9 @@ discard block |
||
6 | 6 | { |
7 | 7 | $files = glob($pattern, $flags); |
8 | 8 | |
9 | - foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) |
|
9 | + foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) |
|
10 | 10 | { |
11 | - $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
|
11 | + $files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | return $files; |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | 'build/humbug.json', |
81 | 81 | 'build/humbug-log.txt', |
82 | 82 | ]; |
83 | - array_map(function ($file) { |
|
83 | + array_map(function($file) { |
|
84 | 84 | @unlink($file); |
85 | 85 | }, $cleanFiles); |
86 | 86 | |
87 | 87 | // So the task doesn't complain, |
88 | 88 | // make any 'missing' dirs to cleanup |
89 | - array_map(function ($dir) { |
|
89 | + array_map(function($dir) { |
|
90 | 90 | if ( ! is_dir($dir)) |
91 | 91 | { |
92 | 92 | `mkdir -p {$dir}`; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | $chunks = array_chunk($files, 6); |
132 | 132 | |
133 | - foreach($chunks as $chunk) |
|
133 | + foreach ($chunks as $chunk) |
|
134 | 134 | { |
135 | 135 | $this->parallelLint($chunk); |
136 | 136 | } |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | ->monitor('composer.json', function() { |
242 | 242 | $this->taskComposerUpdate()->run(); |
243 | 243 | }) |
244 | - ->monitor('src', function () { |
|
244 | + ->monitor('src', function() { |
|
245 | 245 | $this->taskExec('test')->run(); |
246 | 246 | }) |
247 | - ->monitor('tests', function () { |
|
247 | + ->monitor('tests', function() { |
|
248 | 248 | $this->taskExec('test')->run(); |
249 | 249 | }) |
250 | 250 | ->run(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | ->timeout(5) |
296 | 296 | ->printed(FALSE); |
297 | 297 | |
298 | - foreach($chunk as $file) |
|
298 | + foreach ($chunk as $file) |
|
299 | 299 | { |
300 | 300 | $task = $task->process("php -l {$file}"); |
301 | 301 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | $this->taskPhpUnit() |
106 | 106 | ->configFile('build/phpunit.xml') |
107 | - ->printed(true) |
|
107 | + ->printed(TRUE) |
|
108 | 108 | ->run(); |
109 | 109 | } |
110 | 110 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $this->lint(); |
229 | 229 | $this->taskPHPUnit() |
230 | 230 | ->configFile('phpunit.xml') |
231 | - ->printed(true) |
|
231 | + ->printed(TRUE) |
|
232 | 232 | ->run(); |
233 | 233 | } |
234 | 234 |
@@ -54,7 +54,7 @@ |
||
54 | 54 | /** |
55 | 55 | * Generate a hash as a cache key from the current method call |
56 | 56 | * |
57 | - * @param object $object |
|
57 | + * @param Kitsu\Model $object |
|
58 | 58 | * @param string $method |
59 | 59 | * @param array $args |
60 | 60 | * @return string |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Anime List Client |
4 | 4 | * |
@@ -48,7 +48,7 @@ |
||
48 | 48 | /** |
49 | 49 | * Constructor |
50 | 50 | * |
51 | - * @param ContainerInterface $container |
|
51 | + * @param \Aviat\Ion\Di\ContainerInterface $container |
|
52 | 52 | */ |
53 | 53 | public function __construct(ContainerInterface $container) |
54 | 54 | { |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Anime List Client |
4 | 4 | * |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * This is a dirty hack until I can fully track down where |
51 | 51 | * the dual-encoding happens |
52 | 52 | * |
53 | - * @param FormBody $formBody The form builder object to fix |
|
53 | + * @param \Amp\Artax\FormBody $formBody The form builder object to fix |
|
54 | 54 | * @return string |
55 | 55 | */ |
56 | 56 | private function fixBody(FormBody $formBody): string |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | /** |
158 | 158 | * Remove some boilerplate for get requests |
159 | 159 | * |
160 | - * @param array $args |
|
160 | + * @param string $args |
|
161 | 161 | * @return array |
162 | 162 | */ |
163 | 163 | protected function getRequest(...$args): array |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Anime List Client |
4 | 4 | * |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | $config = $this->container->get('config'); |
83 | 83 | $logger = $this->container->getLogger('mal_request'); |
84 | 84 | |
85 | - $headers = array_merge($this->defaultHeaders, $options['headers'] ?? [], [ |
|
85 | + $headers = array_merge($this->defaultHeaders, $options['headers'] ?? [], [ |
|
86 | 86 | 'Authorization' => 'Basic ' . |
87 | - base64_encode($config->get(['mal','username']) . ':' .$config->get(['mal','password'])) |
|
87 | + base64_encode($config->get(['mal', 'username']) . ':' . $config->get(['mal', 'password'])) |
|
88 | 88 | ]); |
89 | 89 | |
90 | 90 | $query = $options['query'] ?? []; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $response = $this->getResponse($type, $url, $options); |
145 | 145 | |
146 | - if ((int) $response->getStatus() > 299 || (int) $response->getStatus() < 200) |
|
146 | + if ((int)$response->getStatus() > 299 || (int)$response->getStatus() < 200) |
|
147 | 147 | { |
148 | 148 | if ($logger) |
149 | 149 | { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
154 | - return XML::toArray((string) $response->getBody()); |
|
154 | + return XML::toArray((string)$response->getBody()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $response = $this->getResponse('POST', ...$args); |
183 | 183 | $validResponseCodes = [200, 201]; |
184 | 184 | |
185 | - if ( ! in_array((int) $response->getStatus(), $validResponseCodes)) |
|
185 | + if ( ! in_array((int)$response->getStatus(), $validResponseCodes)) |
|
186 | 186 | { |
187 | 187 | if ($logger) |
188 | 188 | { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | private function request(string $type, string $url, array $options = []): array |
137 | 137 | { |
138 | - $logger = null; |
|
138 | + $logger = NULL; |
|
139 | 139 | if ($this->getContainer()) |
140 | 140 | { |
141 | 141 | $logger = $this->container->getLogger('mal_request'); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | protected function postRequest(...$args): array |
175 | 175 | { |
176 | - $logger = null; |
|
176 | + $logger = NULL; |
|
177 | 177 | if ($this->getContainer()) |
178 | 178 | { |
179 | 179 | $logger = $this->container->getLogger('mal_request'); |