Skip to content

Commit 6d338c5

Browse files
author
Ievgen Shakhsuvarov
committed
MAGETWO-32710: Code micro-optimizations
- PHPCS sniff
1 parent 87bf81d commit 6d338c5

File tree

1 file changed

+36
-0
lines changed
  • dev/tests/static/framework/Magento/Sniffs/MicroOptimizations

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sniffs\MicroOptimizations;
7+
8+
use PHP_CodeSniffer_File;
9+
use PHP_CodeSniffer_Sniff;
10+
11+
class IsNullSniff implements PHP_CodeSniffer_Sniff
12+
{
13+
/**
14+
* @var string
15+
*/
16+
protected $blacklist = 'is_null';
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function register()
22+
{
23+
return [T_STRING];
24+
}
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function process(PHP_CodeSniffer_File $sourceFile, $stackPtr)
30+
{
31+
$tokens = $sourceFile->getTokens();
32+
if ($tokens[$stackPtr]['content'] === $this->blacklist) {
33+
$sourceFile->addError("is_null should be avoided. Use strict comparison instead.", $stackPtr);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)