-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw if a variadic parameter contains unexpected named arguments (#1…
- Loading branch information
Showing
4 changed files
with
91 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Internal; | ||
|
||
use BadMethodCallException; | ||
|
||
use function array_filter; | ||
use function array_is_list; | ||
use function array_keys; | ||
use function array_values; | ||
use function assert; | ||
use function debug_backtrace; | ||
use function implode; | ||
use function is_string; | ||
use function sprintf; | ||
|
||
use const DEBUG_BACKTRACE_IGNORE_ARGS; | ||
|
||
/** | ||
* Checks if a variadic parameter contains unexpected named arguments. | ||
* | ||
* @internal | ||
*/ | ||
trait NoUnknownNamedArguments | ||
{ | ||
/** | ||
* @param TItem[] $parameter | ||
* | ||
* @template TItem | ||
* @psalm-assert list<TItem> $parameter | ||
*/ | ||
private static function validateVariadicParameter(array $parameter): void | ||
{ | ||
if (array_is_list($parameter)) { | ||
return; | ||
} | ||
|
||
[, $trace] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); | ||
assert(isset($trace['class'])); | ||
|
||
$additionalArguments = array_values(array_filter( | ||
array_keys($parameter), | ||
is_string(...), | ||
)); | ||
|
||
throw new BadMethodCallException(sprintf( | ||
'Invalid call to %s::%s(), unknown named arguments: %s', | ||
$trace['class'], | ||
$trace['function'], | ||
implode(', ', $additionalArguments), | ||
)); | ||
} | ||
} |
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