Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.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_InfoFiles_RequiredSniff. | |
4 * | |
5 * @category PHP | |
6 * @package PHP_CodeSniffer | |
7 * @link http://pear.php.net/package/PHP_CodeSniffer | |
8 */ | |
9 | |
10 /** | |
11 * "name", "description" and "core are required fields in Drupal info files. Also | |
12 * checks the "php" minimum requirement for Drupal 7. | |
13 * | |
14 * @category PHP | |
15 * @package PHP_CodeSniffer | |
16 * @link http://pear.php.net/package/PHP_CodeSniffer | |
17 */ | |
18 class Drupal_Sniffs_InfoFiles_RequiredSniff implements PHP_CodeSniffer_Sniff | |
19 { | |
20 | |
21 | |
22 /** | |
23 * Returns an array of tokens this test wants to listen for. | |
24 * | |
25 * @return array | |
26 */ | |
27 public function register() | |
28 { | |
29 return array(T_INLINE_HTML); | |
30 | |
31 }//end register() | |
32 | |
33 | |
34 /** | |
35 * Processes this test, when one of its tokens is encountered. | |
36 * | |
37 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. | |
38 * @param int $stackPtr The position of the current token in the | |
39 * stack passed in $tokens. | |
40 * | |
41 * @return int | |
42 */ | |
43 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
44 { | |
45 // Only run this sniff once per info file. | |
46 $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4)); | |
47 if ($fileExtension !== 'info') { | |
48 return ($phpcsFile->numTokens + 1); | |
49 } | |
50 | |
51 $contents = file_get_contents($phpcsFile->getFilename()); | |
52 $info = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat($contents); | |
53 if (isset($info['name']) === false) { | |
54 $error = '"name" property is missing in the info file'; | |
55 $phpcsFile->addError($error, $stackPtr, 'Name'); | |
56 } | |
57 | |
58 if (isset($info['description']) === false) { | |
59 $error = '"description" property is missing in the info file'; | |
60 $phpcsFile->addError($error, $stackPtr, 'Description'); | |
61 } | |
62 | |
63 if (isset($info['core']) === false) { | |
64 $error = '"core" property is missing in the info file'; | |
65 $phpcsFile->addError($error, $stackPtr, 'Core'); | |
66 } else if ($info['core'] === '7.x' && isset($info['php']) === true | |
67 && $info['php'] <= '5.2' | |
68 ) { | |
69 $error = 'Drupal 7 core already requires PHP 5.2'; | |
70 $ptr = Drupal_Sniffs_InfoFiles_ClassFilesSniff::getPtr('php', $info['php'], $phpcsFile); | |
71 $phpcsFile->addError($error, $ptr, 'D7PHPVersion'); | |
72 } | |
73 | |
74 return ($phpcsFile->numTokens + 1); | |
75 | |
76 }//end process() | |
77 | |
78 | |
79 }//end class |