-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathEmptyBlockSniff.php
57 lines (52 loc) · 1.47 KB
/
EmptyBlockSniff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Copyright 2018 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\CodeAnalysis;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff;
/**
* Detects possible empty blocks.
*/
class EmptyBlockSniff extends EmptyStatementSniff
{
/**
* @inheritdoc
*/
public function register()
{
return array_merge(
parent::register(),
[
T_FUNCTION,
T_TRAIT
]
);
}
/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (
$tokens[$stackPtr]['code'] === T_FUNCTION &&
strpos($phpcsFile->getDeclarationName($stackPtr), 'around') === 0
) {
return;
}
// Ignore empty constructor function blocks when using property promotion
if (
$tokens[$stackPtr]['code'] === T_FUNCTION &&
strpos($phpcsFile->getDeclarationName($stackPtr), '__construct') === 0 &&
count($phpcsFile->getMethodParameters($stackPtr)) > 0 &&
array_reduce($phpcsFile->getMethodParameters($stackPtr), static function ($result, $methodParam) {
return $result && isset($methodParam['property_visibility']);
}, true)
) {
return;
}
parent::process($phpcsFile, $stackPtr);
}//end process()
}