Commas in create() function of classes breaks composer autoload

Created on 13 May 2024, 11 months ago

Problem/Motivation

I am sure this is more about server-side configuration but it looks like commas before closing parenthesis in create() functions of classes somehow breaks composer autoload function.

The errors is:

ParseError: syntax error, unexpected ')' in Composer\Autoload\includeFile() (line 66 of modules/select_or_other/src/Plugin/Field/FieldWidget/ReferenceWidget.php).

When installing the module I needed to manually fix following files:

ReferenceWidget.php

  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $plugin_id,
      $plugin_definition,
      $configuration['field_definition'],
      $configuration['settings'],
      $configuration['third_party_settings'],
      $container->get('entity_type.manager'),
      $container->get('entity_type.bundle.info'),
      $container->get('current_user'), // Removing this comma
    );
  }

ListWidget.php

  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $plugin_id,
      $plugin_definition,
      $configuration['field_definition'],
      $configuration['settings'],
      $configuration['third_party_settings'],
      $container->get('current_user'),
      $container->get('entity_type.manager'), // Removing this comma
    );
  }

After removing the commas autoload loads files well and everything works as intended.

Steps to reproduce

It might as well be related to older version of Drupal. On this project I run Drupal 8.9.13 and PHP 7.2.24

Proposed resolution

I am not sure how to write the patch but it seems to be a simple fix which will not break anything anywhere else.

🐛 Bug report
Status

Needs review

Version

4.1

Component

Code

Created by

🇸🇰Slovakia lubwn

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024