Skip to content

Commit

Permalink
Fixed issue where calling a function with an array was always conside…
Browse files Browse the repository at this point in the history
…red disallowed when using disallowParams.
  • Loading branch information
mad-briller authored and spaze committed Mar 19, 2023
1 parent 6bb5575 commit 97242a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/Calls/FunctionCallsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ protected function getRule(): Rule
1 => Blade::class,
],
],
[
'function' => '\Foo\Bar\Waldo\config()',
'allowIn' => [
'../src/disallowed-allow/*.php',
'../src/*-allow/*.*',
],
'disallowParams' => [
1 => 'string-key',
],
],
]
);
}
Expand Down Expand Up @@ -287,6 +297,10 @@ public function testRule(): void
'Calling Foo\Bar\Waldo\mocky() is forbidden, mocking Blade is not allowed.',
83,
],
[
'Calling Foo\Bar\Waldo\config() is forbidden, because reasons',
91,
],
]);
// Based on the configuration above, no errors in this file:
$this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], [
Expand Down
8 changes: 8 additions & 0 deletions tests/libs/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ function waldo(string $name = '', string $value = '', int $expires = 0, string $
function mocky(string $className): void
{
}


/**
* @param array|string|null $key
*/
function config($key = null)
{
}
5 changes: 5 additions & 0 deletions tests/src/disallowed-allow/functionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@

// not disallowed
hash((new stdClass())->property . 'foo', 'NAH');

// not disallowed param
\Foo\Bar\Waldo\config(['key' => 'string']);
// allowed by path
\Foo\Bar\Waldo\config('string-key');
5 changes: 5 additions & 0 deletions tests/src/disallowed/functionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@

// not disallowed
hash((new stdClass())->property . 'foo', 'NAH');

// not disallowed param
\Foo\Bar\Waldo\config(['key' => 'string']);
// disallowed param
\Foo\Bar\Waldo\config('string-key');

0 comments on commit 97242a4

Please sign in to comment.