Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | 1 <?php |
2 /** | 2 /** |
3 * DrupalPractice_Sniffs_General_ClassNameSniff | 3 * \DrupalPractice\Sniffs\General\ClassNameSniff |
4 * | 4 * |
5 * @category PHP | 5 * @category PHP |
6 * @package PHP_CodeSniffer | 6 * @package PHP_CodeSniffer |
7 * @link http://pear.php.net/package/PHP_CodeSniffer | 7 * @link http://pear.php.net/package/PHP_CodeSniffer |
8 */ | 8 */ |
9 | |
10 namespace DrupalPractice\Sniffs\General; | |
11 | |
12 use PHP_CodeSniffer\Files\File; | |
13 use PHP_CodeSniffer\Sniffs\Sniff; | |
14 use DrupalPractice\Project; | |
9 | 15 |
10 /** | 16 /** |
11 * Checks that classes without namespaces are properly prefixed with the module | 17 * Checks that classes without namespaces are properly prefixed with the module |
12 * name. | 18 * name. |
13 * | 19 * |
14 * @category PHP | 20 * @category PHP |
15 * @package PHP_CodeSniffer | 21 * @package PHP_CodeSniffer |
16 * @link http://pear.php.net/package/PHP_CodeSniffer | 22 * @link http://pear.php.net/package/PHP_CodeSniffer |
17 */ | 23 */ |
18 class DrupalPractice_Sniffs_General_ClassNameSniff implements PHP_CodeSniffer_Sniff | 24 class ClassNameSniff implements Sniff |
19 { | 25 { |
20 | 26 |
21 | 27 |
22 /** | 28 /** |
23 * Returns an array of tokens this test wants to listen for. | 29 * Returns an array of tokens this test wants to listen for. |
35 | 41 |
36 | 42 |
37 /** | 43 /** |
38 * Processes this test, when one of its tokens is encountered. | 44 * Processes this test, when one of its tokens is encountered. |
39 * | 45 * |
40 * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. | 46 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
41 * @param int $stackPtr The position of the current token | 47 * @param int $stackPtr The position of the function |
42 * in the stack passed in $tokens. | 48 * name in the stack. |
43 * | 49 * |
44 * @return void | 50 * @return void |
45 */ | 51 */ |
46 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | 52 public function process(File $phpcsFile, $stackPtr) |
47 { | 53 { |
48 // If there is a PHP 5.3 namespace declaration in the file we return | 54 // If there is a PHP 5.3 namespace declaration in the file we return |
49 // immediately as classes can be named arbitrary within a namespace. | 55 // immediately as classes can be named arbitrary within a namespace. |
50 $namespace = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1)); | 56 $namespace = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1)); |
51 if ($namespace !== false) { | 57 if ($namespace !== false) { |
52 return; | 58 return; |
53 } | 59 } |
54 | 60 |
55 $moduleName = DrupalPractice_Project::getName($phpcsFile); | 61 $moduleName = Project::getName($phpcsFile); |
56 if ($moduleName === false) { | 62 if ($moduleName === false) { |
57 return; | 63 return; |
58 } | 64 } |
59 | 65 |
60 $tokens = $phpcsFile->getTokens(); | 66 $tokens = $phpcsFile->getTokens(); |