@Mile23 reported in #1999722-28: [policy] Define coding standards for anonymous functions (closures) that there is a piece of code currently in ConfigManager that gets wrongly auto-fixed by Drupal.WhiteSpace.ScopeClosingBrace:

    foreach (['config', 'content'] as $dependency_type) {
      $affected_dependencies[$dependency_type] = array_combine(
        array_map(function ($entity) { return $entity->getConfigDependencyName(); }, $affected_dependencies[$dependency_type]),
        $affected_dependencies[$dependency_type]
      );
    }

The body of the anonymous function should not be inlined here. It currently gets autofixed to this:

    foreach (['config', 'content'] as $dependency_type) {
      $affected_dependencies[$dependency_type] = array_combine(
        array_map(function ($entity) { return $entity->getConfigDependencyName();
        }, $affected_dependencies[$dependency_type]),
        $affected_dependencies[$dependency_type]
      );
    }

But that still has part of the function body inline. It should be fixed to either this:

    foreach (['config', 'content'] as $dependency_type) {
      $affected_dependencies[$dependency_type] = array_combine(
        array_map(
          function ($entity) {
            return $entity->getConfigDependencyName();
          },
          $affected_dependencies[$dependency_type]
        ),
        $affected_dependencies[$dependency_type]
      );
    }

Or, because it is not required to have each function argument on a separate line, it can also be autofixed to this:

    foreach (['config', 'content'] as $dependency_type) {
      $affected_dependencies[$dependency_type] = array_combine(
        array_map(function ($entity) {
          return $entity->getConfigDependencyName();
        }, $affected_dependencies[$dependency_type]),
        $affected_dependencies[$dependency_type]
      );
    }

The second example is also valid according to coding standards and is possibly easier to target in this fix.

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

klausi’s picture

Status: Active » Closed (works as designed)

You need to run the fixer for closing curly braces AND opening curly braces, then you get the desired autofix (the last code block in the issue summary). The problem is that core only enables part of the Drupal standard, so the fixer can only fix part of the problems.

If you execute the following command then ConfigManager.php will be auto-fixed just fine:
phpcbf --standard=Drupal core/lib/Drupal/Core/Config/ConfigManager.php