Skip to content

Commit 9bdfba7

Browse files
author
Nikolay Shapovalov
committed
test
1 parent ba30df5 commit 9bdfba7

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* \Drupal\Sniffs\Classes\FullyQualifiedNamespaceSniff.
4+
*
5+
* @category PHP
6+
* @package PHP_CodeSniffer
7+
* @link http://pear.php.net/package/PHP_CodeSniffer
8+
*/
9+
10+
namespace Drupal\Sniffs\Classes;
11+
12+
use PHP_CodeSniffer\Files\File;
13+
use PHP_CodeSniffer\Sniffs\Sniff;
14+
15+
/**
16+
* Checks that class references do not use FQN but use statements.
17+
*
18+
* @category PHP
19+
* @package PHP_CodeSniffer
20+
* @link http://pear.php.net/package/PHP_CodeSniffer
21+
*/
22+
class TestSniff implements Sniff
23+
{
24+
25+
26+
/**
27+
* Returns an array of tokens this test wants to listen for.
28+
*
29+
* @return array<int|string>
30+
*/
31+
public function register()
32+
{
33+
return [T_ATTRIBUTE];
34+
35+
}//end register()
36+
37+
38+
/**
39+
* Processes this test, when one of its tokens is encountered.
40+
*
41+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
42+
* token was found.
43+
* @param int $stackPtr The position in the PHP_CodeSniffer
44+
* file's token stack where the token
45+
* was found.
46+
*
47+
* @return void|int Optionally returns a stack pointer. The sniff will not be
48+
* called again on the current file until the returned stack
49+
* pointer is reached. Return $phpcsFile->numTokens + 1 to skip
50+
* the rest of the file.
51+
*/
52+
public function process(File $phpcsFile, $stackPtr)
53+
{
54+
$tokens = $phpcsFile->getTokens();
55+
$end = $phpcsFile->findNext([T_ATTRIBUTE_END], ($stackPtr + 2));
56+
$shortContent = '';
57+
if ()
58+
for ($i = ($stackPtr + 1); $i < $end; $i++) {
59+
$shortContent .= $tokens[$i]['content'];
60+
}
61+
if (preg_match('/^hook\(.hook_/i', $shortContent, $matches) === 1) {
62+
var_dump($matches);
63+
}
64+
65+
}//end process()
66+
67+
68+
}//end class

0 commit comments

Comments
 (0)