(PHPStan) Deprecate calling PluginBase::getConfiguration() with a parameter

Created on 13 July 2024, about 2 months ago

Problem/Motivation

\Drupal\feeds\Plugin\Type\PluginBase::getConfiguration() has an optional parameter with which a certain configuration item can be retrieved. However, this does not comply with the interface \Drupal\Component\Plugin\ConfigurableInterface in which it is stated that the method getConfiguration() always returns an array. When PluginBase::getConfiguration() is called with the optional parameter set, an array won't always be returned. There will be even returned nothing if the requested configuration key does not exist.

This also causes the following warning in PHPStan:

Method Drupal\feeds\Plugin\Type\PluginBase::getConfiguration() should return array but return statement is missing.

The warning is ignored (or will be) in phpstan.neon.

Proposed resolution

Deprecate the optional parameter $key of \Drupal\feeds\Plugin\Type\PluginBase::getConfiguration().
Update all calling code in the Feeds code base by no longer passing a parameter to that method.

$plugin->getConfiguration('foo')

would then be replaced with:

$plugin->getConfiguration()['foo']

Write a change record about this change, but keep supporting the method to be called with a parameter for now.

The deprecation message would be:

Calling PluginBase::getConfiguration() with the $key argument is deprecated in feeds:3.0.0-rc1 and will be removed from feeds:4.0.0. Use $plugin->getConfiguration()['foo'] instead. See https://www.drupal.org/node/xxx '

Where 'xxx' will be the node ID of the change record.

Code:

if (isset($key)) {
  @trigger_error('Calling ' . __METHOD__ . '() with the $key argument is deprecated in feeds:3.0.0-rc1 and will be removed from feeds:4.0.0. Use $plugin->getConfiguration()[\'foo\'] instead. See https://www.drupal.org/node/xxx', E_USER_DEPRECATED);
}

Remaining tasks

  • Draft a change record about this change.
  • Trigger an error with a deprecation message when \Drupal\feeds\Plugin\Type\PluginBase::getConfiguration() is called with a parameter.
  • Update all calls to PluginBase::getConfiguration() to no longer pass a parameter (but do ensure that the same data is retrieved).
  • Commit.
  • Publish the change record.

User interface changes

None.

API changes

The parameter $key in \Drupal\feeds\Plugin\Type\PluginBase::getConfiguration() is kept, but will trigger an error when used.

Data model changes

None.

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇳🇱Netherlands MegaChriz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024