-
-
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.
Make sure
new
calls are also filtered by definedIn (#203)
Ran into some issues with the new `definedIn`, where it would report all `new` calls, to built in classes, as it had no definedIn, and since it wasn't passed along.
- Loading branch information
Showing
6 changed files
with
90 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Spaze\PHPStan\Rules\Disallowed\Calls; | ||
|
||
use PHPStan\File\FileHelper; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\ShouldNotHappenException; | ||
use PHPStan\Testing\RuleTestCase; | ||
use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; | ||
use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; | ||
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; | ||
use Spaze\PHPStan\Rules\Disallowed\File\FilePath; | ||
use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; | ||
use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; | ||
use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; | ||
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; | ||
|
||
class NewCallsDefinedInTest extends RuleTestCase | ||
{ | ||
|
||
/** | ||
* @throws ShouldNotHappenException | ||
*/ | ||
protected function getRule(): Rule | ||
{ | ||
$normalizer = new Normalizer(); | ||
$formatter = new Formatter($normalizer); | ||
$filePath = new FilePath(new FileHelper(__DIR__), __DIR__ . '/..'); | ||
$allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); | ||
return new NewCalls( | ||
new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath), | ||
new DisallowedCallFactory($formatter, $normalizer, $allowed), | ||
[ | ||
[ | ||
'method' => '*', | ||
'definedIn' => 'libs/Bl*', | ||
'allowIn' => [ | ||
'src/disallowed-allow/*.php', | ||
'src/*-allow/*.*', | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
|
||
public function testRule(): void | ||
{ | ||
// Based on the configuration above, in this file: | ||
$this->analyse([__DIR__ . '/../src/disallowed/methodCallsDefinedIn.php'], [ | ||
[ | ||
// expect this error message: | ||
'Calling Waldo\Quux\Blade::__construct() is forbidden, because reasons [Waldo\Quux\Blade::__construct() matches *()]', | ||
// on this line: | ||
9, | ||
], | ||
]); | ||
// Based on the configuration above, no errors in this file: | ||
$this->analyse([__DIR__ . '/../src/disallowed-allow/methodCallsDefinedIn.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
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,8 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Exceptions; | ||
|
||
class TestException extends \Exception | ||
{ | ||
} |
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