-
-
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.
- Loading branch information
Showing
10 changed files
with
145 additions
and
28 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
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,87 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Spaze\PHPStan\Rules\Disallowed\Calls; | ||
|
||
use PHPStan\File\FileHelper; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; | ||
use Spaze\PHPStan\Rules\Disallowed\DisallowedHelper; | ||
use Spaze\PHPStan\Rules\Disallowed\IsAllowedFileHelper; | ||
|
||
/** | ||
* @requires PHP > 8.0 | ||
*/ | ||
class FunctionCallsNamedParamsTest extends RuleTestCase | ||
{ | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return new FunctionCalls( | ||
new DisallowedHelper(new IsAllowedFileHelper(new FileHelper(__DIR__))), | ||
new DisallowedCallFactory(), | ||
[ | ||
[ | ||
'function' => 'setcookie()', | ||
'allowIn' => [ | ||
'../src/disallowed-allowed/*.php', | ||
'../src/*-allow/*.*', | ||
], | ||
'allowParamsAnywhereAnyValue' => [ | ||
'value', | ||
], | ||
'allowParamsInAllowedAnyValue' => [ | ||
'path', | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
|
||
public function testRule(): void | ||
{ | ||
// Based on the configuration above, in this file: | ||
$this->analyse([__DIR__ . '/../src/disallowed/functionCallsNamedParams.php'], [ | ||
[ | ||
// expect this error message: | ||
'Calling setcookie() is forbidden, because reasons', | ||
// on this line: | ||
5, | ||
], | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
6, | ||
], | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
8, | ||
], | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
9, | ||
], | ||
]); | ||
// Based on the configuration above, no errors in this file: | ||
$this->analyse([__DIR__ . '/../src/disallowed-allow/functionCallsNamedParams.php'], [ | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
5, | ||
], | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
6, | ||
], | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
7, | ||
], | ||
[ | ||
'Calling setcookie() is forbidden, because reasons', | ||
8, | ||
], | ||
]); | ||
} | ||
|
||
} |
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,9 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
// fourth/$path param needed | ||
setcookie('foo'); | ||
setcookie('foo', 'bar'); | ||
setcookie('foo', value: 'bar'); | ||
setcookie('foo', 'bar', 0, '/'); | ||
setcookie('foo', 'bar', path: '/'); |
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); | ||
|
||
// second/$value param needed | ||
setcookie('foo'); | ||
setcookie('foo', 'bar'); | ||
setcookie('foo', value: 'bar'); | ||
setcookie('foo', 'bar', 0, '/'); | ||
setcookie('foo', 'bar', path: '/'); |