Issue #3330481 by spokje, quietone, mstrelan, smustgrave: Fix PHPStan L2 error "PHPDoc tag @foo has invalid value (Bar)"

merge-requests/8590/merge
Dave Long 2024-11-02 22:48:59 +00:00
parent fa4cdaf3f2
commit 5a87e35f8f
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
15 changed files with 36 additions and 52 deletions

View File

@ -47,7 +47,7 @@ class Plugin implements PluginInterface, EventSubscriberInterface, Capable {
/**
* Record whether the 'require' command was called.
*
* @param bool
* @var bool
*/
protected $requireWasCalled;

View File

@ -441,7 +441,7 @@ function drupal_static_reset($name = NULL) {
*
* @param callable $callback
* The shutdown function to register.
* @param ...
* @param ...$args
* Additional arguments to pass to the shutdown function.
*
* @return array
@ -450,7 +450,7 @@ function drupal_static_reset($name = NULL) {
* @see register_shutdown_function()
* @ingroup php_wrappers
*/
function &drupal_register_shutdown_function($callback = NULL) {
function &drupal_register_shutdown_function($callback = NULL, ...$args) {
// We cannot use drupal_static() here because the static cache is reset during
// batch processing, which breaks batch handling.
static $callbacks = [];
@ -460,9 +460,6 @@ function &drupal_register_shutdown_function($callback = NULL) {
if (empty($callbacks)) {
register_shutdown_function('_drupal_shutdown_function');
}
$args = func_get_args();
// Remove $callback from the arguments.
unset($args[0]);
// Save callback and arguments
$callbacks[] = ['callback' => $callback, 'arguments' => $args];
}

View File

@ -184,7 +184,7 @@ class Inspector {
*
* @param mixed $traversable
* Variable to be examined.
* @param string ...
* @param ...$keys
* Keys to be searched for.
*
* @return bool
@ -370,7 +370,7 @@ class Inspector {
*
* @param mixed $traversable
* Variable to be examined.
* @param string ...
* @param ...$classes
* Classes and interfaces to test objects against.
*
* @return bool

View File

@ -286,7 +286,7 @@ class NestedArray {
* $correct = NestedArray::mergeDeep($link_options_1, $link_options_2);
* @endcode
*
* @param array ...
* @param array ...$arrays
* Arrays to merge.
*
* @return array
@ -294,8 +294,8 @@ class NestedArray {
*
* @see NestedArray::mergeDeepArray()
*/
public static function mergeDeep() {
return self::mergeDeepArray(func_get_args());
public static function mergeDeep(...$arrays) {
return self::mergeDeepArray($arrays);
}
/**

View File

@ -19,7 +19,7 @@ class Cache {
/**
* Merges lists of cache contexts and removes duplicates.
*
* @param list<string> ...
* @param list<string> ...$cache_contexts
* Cache contexts to merge.
*
* @return list<string>
@ -42,7 +42,7 @@ class Cache {
* allows items to be invalidated based on all tags attached to the content
* they're constituted from.
*
* @param list<string> ...
* @param list<string> ...$cache_tags
* Cache tags to merge.
*
* @return list<string>
@ -59,7 +59,7 @@ class Cache {
*
* Ensures infinite max-age (Cache::PERMANENT) is taken into account.
*
* @param int ...
* @param int ...$max_ages
* Max age values to merge.
*
* @return int

View File

@ -97,8 +97,8 @@ abstract class ImageToolkitOperationBase extends PluginBase implements ImageTool
* @return array
* The prepared arguments array.
*
* @throws \InvalidArgumentException.
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException.
* @throws \InvalidArgumentException
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
protected function prepareArguments(array $arguments) {
foreach ($this->arguments() as $id => $argument) {

View File

@ -174,13 +174,12 @@ class Attribute implements \ArrayAccess, \IteratorAggregate, MarkupInterface {
/**
* Adds classes or merges them on to array of existing CSS classes.
*
* @param string|array ...
* @param string|array ...$args
* CSS classes to add to the class attribute array.
*
* @return $this
*/
public function addClass() {
$args = func_get_args();
public function addClass(...$args) {
if ($args) {
$classes = [];
foreach ($args as $arg) {
@ -237,13 +236,12 @@ class Attribute implements \ArrayAccess, \IteratorAggregate, MarkupInterface {
/**
* Removes an attribute from an Attribute object.
*
* @param string|array ...
* @param string|array ...$args
* Attributes to remove from the attribute array.
*
* @return $this
*/
public function removeAttribute() {
$args = func_get_args();
public function removeAttribute(...$args) {
foreach ($args as $arg) {
// Support arrays or multiple arguments.
if (is_array($arg)) {
@ -262,15 +260,14 @@ class Attribute implements \ArrayAccess, \IteratorAggregate, MarkupInterface {
/**
* Removes argument values from array of existing CSS classes.
*
* @param string|array ...
* @param string|array ...$args
* CSS classes to remove from the class attribute array.
*
* @return $this
*/
public function removeClass() {
public function removeClass(...$args) {
// With no class attribute, there is no need to remove.
if (isset($this->storage['class']) && $this->storage['class'] instanceof AttributeArray) {
$args = func_get_args();
$classes = [];
foreach ($args as $arg) {
// Merge the values passed in from the classes array.

View File

@ -631,22 +631,20 @@ class TwigExtension extends AbstractExtension {
*
* @param array|object $element
* The parent renderable array to exclude the child items.
* @param string[]|string ...
* @param string[]|string ...$args
* The string keys of $element to prevent printing. Arguments can include
* string keys directly, or arrays of string keys to hide.
*
* @return array
* The filtered renderable array.
*/
public function withoutFilter($element) {
public function withoutFilter($element, ...$args) {
if ($element instanceof \ArrayAccess) {
$filtered_element = clone $element;
}
else {
$filtered_element = $element;
}
$args = func_get_args();
unset($args[0]);
// Since the remaining arguments can be a mix of arrays and strings, we use
// some native PHP iterator classes to allow us to recursively iterate over
// everything in a single pass.

View File

@ -563,7 +563,7 @@ class Url implements TrustedCallbackInterface {
*
* @return string
*
* @throws \UnexpectedValueException.
* @throws \UnexpectedValueException
* If this is a URI with no corresponding route.
*/
public function getRouteName() {
@ -579,7 +579,7 @@ class Url implements TrustedCallbackInterface {
*
* @return array
*
* @throws \UnexpectedValueException.
* @throws \UnexpectedValueException
* If this is a URI with no corresponding route.
*/
public function getRouteParameters() {
@ -598,7 +598,7 @@ class Url implements TrustedCallbackInterface {
*
* @return $this
*
* @throws \UnexpectedValueException.
* @throws \UnexpectedValueException
* If this is a URI with no corresponding route.
*/
public function setRouteParameters($parameters) {
@ -619,7 +619,7 @@ class Url implements TrustedCallbackInterface {
*
* @return $this
*
* @throws \UnexpectedValueException.
* @throws \UnexpectedValueException
* If this is a URI with no corresponding route.
*/
public function setRouteParameter($key, $value) {
@ -777,7 +777,7 @@ class Url implements TrustedCallbackInterface {
* @return string
* The internal path for this route.
*
* @throws \UnexpectedValueException.
* @throws \UnexpectedValueException
* If this is a URI with no corresponding system path.
*/
public function getInternalPath() {

View File

@ -160,7 +160,7 @@ class UpdateFetcherTest extends UnitTestCase {
/**
* Mocks the HTTP client.
*
* @param \GuzzleHttp\Psr7\Response ...
* @param \GuzzleHttp\Psr7\Response ...$responses
* Variable number of Response objects that the mocked client should return.
*/
protected function mockClient(Response ...$responses): void {

View File

@ -726,18 +726,14 @@ function _views_query_tag_alter_condition(AlterableInterface $query, &$condition
* @param $display_id
* The display id to embed. If unsure, use 'default', as it will always be
* valid. But things like 'page' or 'block' should work here.
* @param ...
* @param ...$args
* Any additional parameters will be passed as arguments.
*
* @return array|null
* A renderable array containing the view output or NULL if the display ID
* of the view to be executed doesn't exist.
*/
function views_embed_view($name, $display_id = 'default') {
$args = func_get_args();
// Remove $name and $display_id from the arguments.
unset($args[0], $args[1]);
function views_embed_view($name, $display_id = 'default', ...$args) {
$view = Views::getView($name);
if (!$view || !$view->access($display_id)) {
return;
@ -763,17 +759,13 @@ function views_embed_view($name, $display_id = 'default') {
* want to use. A URL will appear in the status bar of your browser. This is
* usually at the bottom of the window, in the chrome. Everything after
* #views-tab- is the display ID, e.g. page_1.
* @param ...
* @param ...$args
* Any additional parameters will be passed as arguments.
*
* @return array
* An array containing an object for each view item.
*/
function views_get_view_result($name, $display_id = NULL) {
$args = func_get_args();
// Remove $name and $display_id from the arguments.
unset($args[0], $args[1]);
function views_get_view_result($name, $display_id = NULL, ...$args) {
$view = Views::getView($name);
if (is_object($view)) {
if (is_array($args)) {

View File

@ -60,7 +60,7 @@ interface StateInterface {
* @return \Drupal\workflows\TransitionInterface
* The Transition object for the provided state ID.
*
* @throws \InvalidArgumentException()
* @throws \InvalidArgumentException
* Exception thrown when the provided state ID can not be transitioned to.
*/
public function getTransitionTo($to_state_id);

View File

@ -5,7 +5,7 @@
* @file
* Drupal hash script - to generate a hash from a plaintext password
*
* @param password1 [password2 [password3 ...]]
* @param string[] ...$password
* Plain-text passwords in quotes (or with spaces backslash escaped).
*
* @todo Port to a console command. https://www.drupal.org/node/2289409

View File

@ -68,14 +68,14 @@ class LibraryDiscoveryParserTest extends UnitTestCase {
/**
* The mocked stream wrapper manager.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface||\PHPUnit\Framework\MockObject\MockObject
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $streamWrapperManager;
/**
* The mocked libraries directory file finder.
*
* @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder||\PHPUnit\Framework\MockObject\MockObject
* @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder|\PHPUnit\Framework\MockObject\MockObject
*/
protected $librariesDirectoryFileFinder;

View File

@ -42,7 +42,7 @@ class AccessAwareRouterTest extends UnitTestCase {
protected $accessManager;
/**
* @var \Drupal\Core\Session\AccountInterface||\PHPUnit\Framework\MockObject\MockObject
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $currentUser;