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