@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * Model for handling requests dealing with the manga list |
25 | 25 | */ |
26 | -class Manga extends API |
|
27 | -{ |
|
26 | +class Manga extends API { |
|
28 | 27 | |
29 | 28 | const READING = 'Reading'; |
30 | 29 | const PLAN_TO_READ = 'Plan to Read'; |
@@ -160,12 +159,14 @@ discard block |
||
160 | 159 | self::COMPLETED => [], |
161 | 160 | ]; |
162 | 161 | |
163 | - foreach ($data as &$entry) { |
|
162 | + foreach ($data as &$entry) |
|
163 | + { |
|
164 | 164 | $key = $this->status_map[$entry['reading_status']]; |
165 | 165 | $output[$key][] = $entry; |
166 | 166 | } |
167 | 167 | |
168 | - foreach ($output as &$val) { |
|
168 | + foreach ($output as &$val) |
|
169 | + { |
|
169 | 170 | $this->sortByName($val, 'manga'); |
170 | 171 | } |
171 | 172 |
@@ -53,7 +53,8 @@ |
||
53 | 53 | * Anime constructor. |
54 | 54 | * @param ContainerInterface $container |
55 | 55 | */ |
56 | - public function __construct(ContainerInterface $container) { |
|
56 | + public function __construct(ContainerInterface $container) |
|
57 | + { |
|
57 | 58 | parent::__construct($container); |
58 | 59 | |
59 | 60 | $config = $container->get('config'); |
@@ -20,22 +20,22 @@ |
||
20 | 20 | * Base trait for api interaction |
21 | 21 | */ |
22 | 22 | trait GuzzleTrait { |
23 | - /** |
|
24 | - * The Guzzle http client object |
|
25 | - * @var object |
|
26 | - */ |
|
27 | - protected $client; |
|
23 | + /** |
|
24 | + * The Guzzle http client object |
|
25 | + * @var object |
|
26 | + */ |
|
27 | + protected $client; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Cookie jar object for api requests |
|
31 | - * @var object |
|
32 | - */ |
|
33 | - protected $cookieJar; |
|
29 | + /** |
|
30 | + * Cookie jar object for api requests |
|
31 | + * @var object |
|
32 | + */ |
|
33 | + protected $cookieJar; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Set up the class properties |
|
37 | - * |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - abstract protected function init(); |
|
35 | + /** |
|
36 | + * Set up the class properties |
|
37 | + * |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + abstract protected function init(); |
|
41 | 41 | } |
42 | 42 | \ No newline at end of file |
@@ -19,7 +19,7 @@ |
||
19 | 19 | /** |
20 | 20 | * Base trait for api interaction |
21 | 21 | */ |
22 | -trait GuzzleTrait { |
|
22 | +trait GuzzleTrait { |
|
23 | 23 | /** |
24 | 24 | * The Guzzle http client object |
25 | 25 | * @var object |
@@ -289,7 +289,8 @@ |
||
289 | 289 | |
290 | 290 | $params = []; |
291 | 291 | |
292 | - switch($failure->failedRule) { |
|
292 | + switch($failure->failedRule) |
|
293 | + { |
|
293 | 294 | case 'Aura\Router\Rule\Allows': |
294 | 295 | $params = [ |
295 | 296 | 'http_code' => 405, |
@@ -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 | ?> |
@@ -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; |
@@ -34,71 +34,71 @@ |
||
34 | 34 | |
35 | 35 | class AbstractClosingCommentSniff implements Sniff |
36 | 36 | { |
37 | - /** |
|
38 | - * As an abstract class, this sniff is not associated to any token. |
|
39 | - */ |
|
40 | - public function register() |
|
41 | - { |
|
42 | - return array(); |
|
43 | - } |
|
37 | + /** |
|
38 | + * As an abstract class, this sniff is not associated to any token. |
|
39 | + */ |
|
40 | + public function register() |
|
41 | + { |
|
42 | + return array(); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * As an abstract class, this sniff is not dedicated to process a token. |
|
47 | - */ |
|
48 | - public function process(File $phpcsFile, $stackPtr) |
|
49 | - { |
|
50 | - $error = __CLASS__.'::'.__METHOD__.' is abstract. Please develop this method in a child class.'; |
|
51 | - throw new PHP_CodeSniffer_Exception($error); |
|
52 | - } |
|
45 | + /** |
|
46 | + * As an abstract class, this sniff is not dedicated to process a token. |
|
47 | + */ |
|
48 | + public function process(File $phpcsFile, $stackPtr) |
|
49 | + { |
|
50 | + $error = __CLASS__.'::'.__METHOD__.' is abstract. Please develop this method in a child class.'; |
|
51 | + throw new PHP_CodeSniffer_Exception($error); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns the comment without its delimiter(s) as well as leading |
|
56 | - * and traling whitespaces. |
|
57 | - * |
|
58 | - * It removes the first #, the two first / (i.e. //) or the first /* |
|
59 | - * and last \*\/. If a comment starts with /**, then the last * will remain |
|
60 | - * as well as whitespaces between this star and the comment content. |
|
61 | - * |
|
62 | - * @param string $comment Comment containing either comment delimiter(s) and |
|
63 | - * trailing or leading whitspaces to clean. |
|
64 | - * |
|
65 | - * @return string Comment without comment delimiter(s) and whitespaces. |
|
66 | - */ |
|
67 | - protected static function _getCommentContent ($comment) |
|
68 | - { |
|
69 | - if (self::_stringStartsWith($comment, '#')) { |
|
70 | - $comment = substr($comment, 1); |
|
71 | - } else if (self::_stringStartsWith($comment, '//')) { |
|
72 | - $comment = substr($comment, 2); |
|
73 | - } else if (self::_stringStartsWith($comment, '/*')) { |
|
74 | - $comment = substr($comment, 2, strlen($comment) - 2 - 2); |
|
75 | - } |
|
76 | - $comment = trim($comment); |
|
77 | - return $comment; |
|
78 | - }//_getCommentContent() |
|
54 | + /** |
|
55 | + * Returns the comment without its delimiter(s) as well as leading |
|
56 | + * and traling whitespaces. |
|
57 | + * |
|
58 | + * It removes the first #, the two first / (i.e. //) or the first /* |
|
59 | + * and last \*\/. If a comment starts with /**, then the last * will remain |
|
60 | + * as well as whitespaces between this star and the comment content. |
|
61 | + * |
|
62 | + * @param string $comment Comment containing either comment delimiter(s) and |
|
63 | + * trailing or leading whitspaces to clean. |
|
64 | + * |
|
65 | + * @return string Comment without comment delimiter(s) and whitespaces. |
|
66 | + */ |
|
67 | + protected static function _getCommentContent ($comment) |
|
68 | + { |
|
69 | + if (self::_stringStartsWith($comment, '#')) { |
|
70 | + $comment = substr($comment, 1); |
|
71 | + } else if (self::_stringStartsWith($comment, '//')) { |
|
72 | + $comment = substr($comment, 2); |
|
73 | + } else if (self::_stringStartsWith($comment, '/*')) { |
|
74 | + $comment = substr($comment, 2, strlen($comment) - 2 - 2); |
|
75 | + } |
|
76 | + $comment = trim($comment); |
|
77 | + return $comment; |
|
78 | + }//_getCommentContent() |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Binary safe string comparison between $needle and |
|
83 | - * the beginning of $haystack. Returns true if $haystack starts with |
|
84 | - * $needle, false otherwise. |
|
85 | - * |
|
86 | - * @param string $haystack The string to search in. |
|
87 | - * @param string $needle The string to search for. |
|
88 | - * |
|
89 | - * @return bool true if $haystack starts with $needle, false otherwise. |
|
90 | - */ |
|
91 | - protected static function _stringStartsWith ($haystack, $needle) |
|
92 | - { |
|
93 | - $startsWith = false; |
|
94 | - if (strlen($needle) <= strlen($haystack)) { |
|
95 | - $haystackBeginning = substr($haystack, 0, strlen($needle)); |
|
96 | - if (0 === strcmp($haystackBeginning, $needle)) { |
|
97 | - $startsWith = true; |
|
98 | - } |
|
99 | - } |
|
100 | - return $startsWith; |
|
101 | - }//_stringStartsWith() |
|
81 | + /** |
|
82 | + * Binary safe string comparison between $needle and |
|
83 | + * the beginning of $haystack. Returns true if $haystack starts with |
|
84 | + * $needle, false otherwise. |
|
85 | + * |
|
86 | + * @param string $haystack The string to search in. |
|
87 | + * @param string $needle The string to search for. |
|
88 | + * |
|
89 | + * @return bool true if $haystack starts with $needle, false otherwise. |
|
90 | + */ |
|
91 | + protected static function _stringStartsWith ($haystack, $needle) |
|
92 | + { |
|
93 | + $startsWith = false; |
|
94 | + if (strlen($needle) <= strlen($haystack)) { |
|
95 | + $haystackBeginning = substr($haystack, 0, strlen($needle)); |
|
96 | + if (0 === strcmp($haystackBeginning, $needle)) { |
|
97 | + $startsWith = true; |
|
98 | + } |
|
99 | + } |
|
100 | + return $startsWith; |
|
101 | + }//_stringStartsWith() |
|
102 | 102 | }//end class |
103 | 103 | |
104 | 104 | ?> |
@@ -32,8 +32,7 @@ discard block |
||
32 | 32 | use PHP_CodeSniffer\Sniffs\Sniff; |
33 | 33 | use PHP_CodeSniffer\Files\File; |
34 | 34 | |
35 | -class AbstractClosingCommentSniff implements Sniff |
|
36 | -{ |
|
35 | +class AbstractClosingCommentSniff implements Sniff { |
|
37 | 36 | /** |
38 | 37 | * As an abstract class, this sniff is not associated to any token. |
39 | 38 | */ |
@@ -66,11 +65,16 @@ discard block |
||
66 | 65 | */ |
67 | 66 | protected static function _getCommentContent ($comment) |
68 | 67 | { |
69 | - if (self::_stringStartsWith($comment, '#')) { |
|
68 | + if (self::_stringStartsWith($comment, '#')) |
|
69 | + { |
|
70 | 70 | $comment = substr($comment, 1); |
71 | - } else if (self::_stringStartsWith($comment, '//')) { |
|
71 | + } |
|
72 | + else if (self::_stringStartsWith($comment, '//')) |
|
73 | + { |
|
72 | 74 | $comment = substr($comment, 2); |
73 | - } else if (self::_stringStartsWith($comment, '/*')) { |
|
75 | + } |
|
76 | + else if (self::_stringStartsWith($comment, '/*')) |
|
77 | + { |
|
74 | 78 | $comment = substr($comment, 2, strlen($comment) - 2 - 2); |
75 | 79 | } |
76 | 80 | $comment = trim($comment); |
@@ -91,9 +95,11 @@ discard block |
||
91 | 95 | protected static function _stringStartsWith ($haystack, $needle) |
92 | 96 | { |
93 | 97 | $startsWith = false; |
94 | - if (strlen($needle) <= strlen($haystack)) { |
|
98 | + if (strlen($needle) <= strlen($haystack)) |
|
99 | + { |
|
95 | 100 | $haystackBeginning = substr($haystack, 0, strlen($needle)); |
96 | - if (0 === strcmp($haystackBeginning, $needle)) { |
|
101 | + if (0 === strcmp($haystackBeginning, $needle)) |
|
102 | + { |
|
97 | 103 | $startsWith = true; |
98 | 104 | } |
99 | 105 | } |
@@ -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 | } |
@@ -36,101 +36,101 @@ |
||
36 | 36 | { |
37 | 37 | |
38 | 38 | |
39 | - public $php5Constructors = '1'; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Constructs the test with the tokens it wishes to listen for. |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true); |
|
50 | - |
|
51 | - }//end __construct() |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Processes this test when one of its tokens is encountered. |
|
56 | - * |
|
57 | - * @param File $phpcsFile The current file being scanned. |
|
58 | - * @param int $stackPtr The position of the current token |
|
59 | - * in the stack passed in $tokens. |
|
60 | - * @param int $currScope A pointer to the start of the scope. |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - protected function processTokenWithinScope( |
|
65 | - File $phpcsFile, |
|
66 | - $stackPtr, |
|
67 | - $currScope |
|
68 | - ) { |
|
69 | - $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
70 | - $className = $phpcsFile->getDeclarationName($currScope); |
|
39 | + public $php5Constructors = '1'; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Constructs the test with the tokens it wishes to listen for. |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true); |
|
50 | + |
|
51 | + }//end __construct() |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Processes this test when one of its tokens is encountered. |
|
56 | + * |
|
57 | + * @param File $phpcsFile The current file being scanned. |
|
58 | + * @param int $stackPtr The position of the current token |
|
59 | + * in the stack passed in $tokens. |
|
60 | + * @param int $currScope A pointer to the start of the scope. |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + protected function processTokenWithinScope( |
|
65 | + File $phpcsFile, |
|
66 | + $stackPtr, |
|
67 | + $currScope |
|
68 | + ) { |
|
69 | + $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
70 | + $className = $phpcsFile->getDeclarationName($currScope); |
|
71 | 71 | |
72 | 72 | $isPhp4Constructor = strcasecmp($methodName, $className) === 0; |
73 | 73 | $isPhp5Constructor = strcasecmp($methodName, '__construct') === 0; |
74 | - if ($this->php5Constructors != '0') { |
|
75 | - if ($isPhp4Constructor) { |
|
76 | - $error = "PHP4 style constructors are not allowed; use \"__construct\" instead"; |
|
77 | - $phpcsFile->addError($error, $stackPtr); |
|
78 | - } |
|
79 | - } else { |
|
80 | - if ($isPhp5Constructor) { |
|
81 | - $error = "PHP5 style constructors are not allowed; use \"$className\" instead"; |
|
82 | - $phpcsFile->addError($error, $stackPtr); |
|
83 | - } |
|
84 | - } |
|
85 | - if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) { |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - $tokens = $phpcsFile->getTokens(); |
|
90 | - |
|
91 | - $parentClassName = $phpcsFile->findExtendedClassName($currScope); |
|
92 | - $wrongConstructor = ''; |
|
93 | - // prepares the error message and wrong constructor |
|
94 | - if ($this->php5Constructors != '0') { |
|
95 | - $error = 'PHP4 style calls to parent constructors are not allowed.'; |
|
96 | - $error = "$error Please use \"parent::__construct\" instead."; |
|
97 | - if (false !== $parentClassName) { |
|
98 | - $wrongConstructor = $parentClassName; |
|
99 | - } |
|
100 | - // Else $wrongConstructor will be empty |
|
101 | - // and the test expression will always be false. |
|
102 | - // It doesn't check that no parent method should be called |
|
103 | - // when no parent class is defined. |
|
104 | - } else { |
|
105 | - $error = 'PHP5 style calls to parent constructors are not allowed.'; |
|
106 | - if (false !== $parentClassName) { |
|
107 | - $error = "$error Please use \"parent::$parentClassName\" instead."; |
|
108 | - } |
|
109 | - $wrongConstructor = '__construct'; |
|
110 | - } |
|
111 | - |
|
112 | - // looks for the use of a wrong constructor. |
|
113 | - $endFunctionIndex = $tokens[$stackPtr]['scope_closer']; |
|
114 | - $doubleColonIndex = $phpcsFile->findNext( |
|
115 | - array(T_DOUBLE_COLON), |
|
116 | - $stackPtr, |
|
117 | - $endFunctionIndex |
|
118 | - ); |
|
119 | - while ($doubleColonIndex) { |
|
120 | - if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING |
|
121 | - && $tokens[($doubleColonIndex + 1)]['content'] === $wrongConstructor |
|
122 | - ) { |
|
123 | - $phpcsFile->addError($error, ($doubleColonIndex + 1)); |
|
124 | - } |
|
125 | - |
|
126 | - $doubleColonIndex = $phpcsFile->findNext( |
|
127 | - array(T_DOUBLE_COLON), |
|
128 | - $doubleColonIndex + 1, |
|
129 | - $endFunctionIndex |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - }//end processTokenWithinScope() |
|
74 | + if ($this->php5Constructors != '0') { |
|
75 | + if ($isPhp4Constructor) { |
|
76 | + $error = "PHP4 style constructors are not allowed; use \"__construct\" instead"; |
|
77 | + $phpcsFile->addError($error, $stackPtr); |
|
78 | + } |
|
79 | + } else { |
|
80 | + if ($isPhp5Constructor) { |
|
81 | + $error = "PHP5 style constructors are not allowed; use \"$className\" instead"; |
|
82 | + $phpcsFile->addError($error, $stackPtr); |
|
83 | + } |
|
84 | + } |
|
85 | + if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) { |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + $tokens = $phpcsFile->getTokens(); |
|
90 | + |
|
91 | + $parentClassName = $phpcsFile->findExtendedClassName($currScope); |
|
92 | + $wrongConstructor = ''; |
|
93 | + // prepares the error message and wrong constructor |
|
94 | + if ($this->php5Constructors != '0') { |
|
95 | + $error = 'PHP4 style calls to parent constructors are not allowed.'; |
|
96 | + $error = "$error Please use \"parent::__construct\" instead."; |
|
97 | + if (false !== $parentClassName) { |
|
98 | + $wrongConstructor = $parentClassName; |
|
99 | + } |
|
100 | + // Else $wrongConstructor will be empty |
|
101 | + // and the test expression will always be false. |
|
102 | + // It doesn't check that no parent method should be called |
|
103 | + // when no parent class is defined. |
|
104 | + } else { |
|
105 | + $error = 'PHP5 style calls to parent constructors are not allowed.'; |
|
106 | + if (false !== $parentClassName) { |
|
107 | + $error = "$error Please use \"parent::$parentClassName\" instead."; |
|
108 | + } |
|
109 | + $wrongConstructor = '__construct'; |
|
110 | + } |
|
111 | + |
|
112 | + // looks for the use of a wrong constructor. |
|
113 | + $endFunctionIndex = $tokens[$stackPtr]['scope_closer']; |
|
114 | + $doubleColonIndex = $phpcsFile->findNext( |
|
115 | + array(T_DOUBLE_COLON), |
|
116 | + $stackPtr, |
|
117 | + $endFunctionIndex |
|
118 | + ); |
|
119 | + while ($doubleColonIndex) { |
|
120 | + if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING |
|
121 | + && $tokens[($doubleColonIndex + 1)]['content'] === $wrongConstructor |
|
122 | + ) { |
|
123 | + $phpcsFile->addError($error, ($doubleColonIndex + 1)); |
|
124 | + } |
|
125 | + |
|
126 | + $doubleColonIndex = $phpcsFile->findNext( |
|
127 | + array(T_DOUBLE_COLON), |
|
128 | + $doubleColonIndex + 1, |
|
129 | + $endFunctionIndex |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + }//end processTokenWithinScope() |
|
134 | 134 | |
135 | 135 | protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
136 | 136 | { |
@@ -32,8 +32,7 @@ discard block |
||
32 | 32 | * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License |
33 | 33 | * @link http://pear.php.net/package/PHP_CodeSniffer |
34 | 34 | */ |
35 | -class ConstructorNameSniff extends AbstractScopeSniff |
|
36 | -{ |
|
35 | +class ConstructorNameSniff extends AbstractScopeSniff { |
|
37 | 36 | |
38 | 37 | |
39 | 38 | public $php5Constructors = '1'; |
@@ -71,18 +70,24 @@ discard block |
||
71 | 70 | |
72 | 71 | $isPhp4Constructor = strcasecmp($methodName, $className) === 0; |
73 | 72 | $isPhp5Constructor = strcasecmp($methodName, '__construct') === 0; |
74 | - if ($this->php5Constructors != '0') { |
|
75 | - if ($isPhp4Constructor) { |
|
73 | + if ($this->php5Constructors != '0') |
|
74 | + { |
|
75 | + if ($isPhp4Constructor) |
|
76 | + { |
|
76 | 77 | $error = "PHP4 style constructors are not allowed; use \"__construct\" instead"; |
77 | 78 | $phpcsFile->addError($error, $stackPtr); |
78 | 79 | } |
79 | - } else { |
|
80 | - if ($isPhp5Constructor) { |
|
80 | + } |
|
81 | + else |
|
82 | + { |
|
83 | + if ($isPhp5Constructor) |
|
84 | + { |
|
81 | 85 | $error = "PHP5 style constructors are not allowed; use \"$className\" instead"; |
82 | 86 | $phpcsFile->addError($error, $stackPtr); |
83 | 87 | } |
84 | 88 | } |
85 | - if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) { |
|
89 | + if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) |
|
90 | + { |
|
86 | 91 | return; |
87 | 92 | } |
88 | 93 | |
@@ -91,19 +96,24 @@ discard block |
||
91 | 96 | $parentClassName = $phpcsFile->findExtendedClassName($currScope); |
92 | 97 | $wrongConstructor = ''; |
93 | 98 | // prepares the error message and wrong constructor |
94 | - if ($this->php5Constructors != '0') { |
|
99 | + if ($this->php5Constructors != '0') |
|
100 | + { |
|
95 | 101 | $error = 'PHP4 style calls to parent constructors are not allowed.'; |
96 | 102 | $error = "$error Please use \"parent::__construct\" instead."; |
97 | - if (false !== $parentClassName) { |
|
103 | + if (false !== $parentClassName) |
|
104 | + { |
|
98 | 105 | $wrongConstructor = $parentClassName; |
99 | 106 | } |
100 | 107 | // Else $wrongConstructor will be empty |
101 | 108 | // and the test expression will always be false. |
102 | 109 | // It doesn't check that no parent method should be called |
103 | 110 | // when no parent class is defined. |
104 | - } else { |
|
111 | + } |
|
112 | + else |
|
113 | + { |
|
105 | 114 | $error = 'PHP5 style calls to parent constructors are not allowed.'; |
106 | - if (false !== $parentClassName) { |
|
115 | + if (false !== $parentClassName) |
|
116 | + { |
|
107 | 117 | $error = "$error Please use \"parent::$parentClassName\" instead."; |
108 | 118 | } |
109 | 119 | $wrongConstructor = '__construct'; |
@@ -116,7 +126,8 @@ discard block |
||
116 | 126 | $stackPtr, |
117 | 127 | $endFunctionIndex |
118 | 128 | ); |
119 | - while ($doubleColonIndex) { |
|
129 | + while ($doubleColonIndex) |
|
130 | + { |
|
120 | 131 | if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING |
121 | 132 | && $tokens[($doubleColonIndex + 1)]['content'] === $wrongConstructor |
122 | 133 | ) { |
@@ -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 |
@@ -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 | } |