-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from localheinz/feature/no-isset-rule
Enhancement: Implement Expressions\NoIssetRule
- Loading branch information
Showing
8 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Andreas M枚ller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/localheinz/phpstan-rules | ||
*/ | ||
|
||
namespace Localheinz\PHPStan\Rules\Expressions; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
|
||
final class NoIssetRule implements Rule | ||
{ | ||
public function getNodeType(): string | ||
{ | ||
return Node\Expr\Isset_::class; | ||
} | ||
|
||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
return [ | ||
'Language construct isset() should not be used.', | ||
]; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Localheinz\PHPStan\Rules\Test\Fixture\Expressions\NoIssetRule\Failure; | ||
|
||
if (isset($foo)) { | ||
echo 'Hello!'; | ||
} |
9 changes: 9 additions & 0 deletions
9
test/Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Localheinz\PHPStan\Rules\Test\Fixture\Expressions\NoIssetRule\Failure; | ||
|
||
if (iSsEt($foo)) { | ||
echo 'Hello!'; | ||
} |
14 changes: 14 additions & 0 deletions
14
test/Fixture/Expressions/NoIssetRule/Success/isset-not-used.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Localheinz\PHPStan\Rules\Test\Fixture\Expressions\NoIssetRule\Success; | ||
|
||
function _isset(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
if (_isset()) { | ||
echo 'Hello!'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Andreas M枚ller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/localheinz/phpstan-rules | ||
*/ | ||
|
||
namespace Localheinz\PHPStan\Rules\Test\Integration\Expressions; | ||
|
||
use Localheinz\PHPStan\Rules\Expressions\NoIssetRule; | ||
use Localheinz\PHPStan\Rules\Test\Integration\AbstractTestCase; | ||
use PHPStan\Rules\Rule; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class NoIssetRuleTest extends AbstractTestCase | ||
{ | ||
public function providerAnalysisSucceeds(): \Generator | ||
{ | ||
$paths = [ | ||
'isset-not-used' => __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Success/isset-not-used.php', | ||
]; | ||
|
||
foreach ($paths as $description => $path) { | ||
yield $description => [ | ||
$path, | ||
]; | ||
} | ||
} | ||
|
||
public function providerAnalysisFails(): \Generator | ||
{ | ||
$paths = [ | ||
'isset-used-with-correct-case' => [ | ||
__DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php', | ||
[ | ||
'Language construct isset() should not be used.', | ||
7, | ||
], | ||
], | ||
'isset-used-with-incorrect-case' => [ | ||
__DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php', | ||
[ | ||
'Language construct isset() should not be used.', | ||
7, | ||
], | ||
], | ||
]; | ||
|
||
foreach ($paths as $description => [$path, $error]) { | ||
yield $description => [ | ||
$path, | ||
$error, | ||
]; | ||
} | ||
} | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return new NoIssetRule(); | ||
} | ||
} |