Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /** | |
3 * Drupal_Sniffs_NamingConventions_ValidClassNameSniff. | |
4 * | |
5 * @category PHP | |
6 * @package PHP_CodeSniffer | |
7 * @author Greg Sherwood <gsherwood@squiz.net> | |
8 * @author Marc McIntyre <mmcintyre@squiz.net> | |
9 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) | |
10 * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence | |
11 * @link http://pear.php.net/package/PHP_CodeSniffer | |
12 */ | |
13 | |
14 /** | |
15 * Drupal_Sniffs_NamingConventions_ValidClassNameSniff. | |
16 * | |
17 * Ensures class and interface names start with a capital letter | |
18 * and do not use _ separators. | |
19 * | |
20 * @category PHP | |
21 * @package PHP_CodeSniffer | |
22 * @author Greg Sherwood <gsherwood@squiz.net> | |
23 * @author Marc McIntyre <mmcintyre@squiz.net> | |
24 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) | |
25 * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence | |
26 * @version Release: 1.2.0RC3 | |
27 * @link http://pear.php.net/package/PHP_CodeSniffer | |
28 */ | |
29 class Drupal_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff | |
30 { | |
31 | |
32 | |
33 /** | |
34 * Returns an array of tokens this test wants to listen for. | |
35 * | |
36 * @return array | |
37 */ | |
38 public function register() | |
39 { | |
40 return array( | |
41 T_CLASS, | |
42 T_INTERFACE, | |
43 ); | |
44 | |
45 }//end register() | |
46 | |
47 | |
48 /** | |
49 * Processes this test, when one of its tokens is encountered. | |
50 * | |
51 * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. | |
52 * @param int $stackPtr The position of the current token | |
53 * in the stack passed in $tokens. | |
54 * | |
55 * @return void | |
56 */ | |
57 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
58 { | |
59 $tokens = $phpcsFile->getTokens(); | |
60 | |
61 $className = $phpcsFile->findNext(T_STRING, $stackPtr); | |
62 $name = trim($tokens[$className]['content']); | |
63 $errorData = array(ucfirst($tokens[$stackPtr]['content'])); | |
64 | |
65 // Make sure the first letter is a capital. | |
66 if (preg_match('|^[A-Z]|', $name) === 0) { | |
67 $error = '%s name must begin with a capital letter'; | |
68 $phpcsFile->addError($error, $stackPtr, 'StartWithCaptial', $errorData); | |
69 } | |
70 | |
71 // Search for underscores. | |
72 if (strpos($name, '_') !== false) { | |
73 $error = '%s name must use UpperCamel naming without underscores'; | |
74 $phpcsFile->addError($error, $stackPtr, 'NoUnderscores', $errorData); | |
75 } | |
76 | |
77 }//end process() | |
78 | |
79 | |
80 }//end class |