comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.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 * "version", "project" and "timestamp" are added automatically by drupal.org 17 * "version", "project" and "timestamp" are added automatically by drupal.org
12 * packaging scripts. 18 * packaging scripts.
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_AutoAddedKeysSniff implements PHP_CodeSniffer_Sniff 24 class AutoAddedKeysSniff 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 if (preg_match('/\.info$/', $phpcsFile->getFilename()) === 1) { 52 if (preg_match('/\.info$/', $phpcsFile->getFilename()) === 1) {
47 // Drupal 7 style info file. 53 // Drupal 7 style info file.
48 $contents = file_get_contents($phpcsFile->getFilename()); 54 $contents = file_get_contents($phpcsFile->getFilename());
49 $info = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat($contents); 55 $info = ClassFilesSniff::drupalParseInfoFormat($contents);
50 } else if (preg_match('/\.info\.yml$/', $phpcsFile->getFilename()) === 1) { 56 } else if (preg_match('/\.info\.yml$/', $phpcsFile->getFilename()) === 1) {
51 // Drupal 8 style info.yml file. 57 // Drupal 8 style info.yml file.
52 $contents = file_get_contents($phpcsFile->getFilename()); 58 $contents = file_get_contents($phpcsFile->getFilename());
53 try { 59 try {
54 $info = \Symfony\Component\Yaml\Yaml::parse($contents); 60 $info = \Symfony\Component\Yaml\Yaml::parse($contents);