Skip to content

optimize-autoloader fails with Enums #10521

@cxj

Description

@cxj

My composer.json:

{
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    },
    "config": {
        "optimize-autoloader": true
    }
}

Output of composer diagnose:

Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: OK
Composer version: 2.2.6
PHP version: 8.1.2
PHP binary path: /usr/local/Cellar/php/8.1.2/bin/php
OpenSSL version: OpenSSL 1.1.1m  14 Dec 2021
cURL version: 7.81.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1m
zip: extension present, unzip present, 7-Zip not available

When I run this command:

composer dumpautoload

I get the following output:

Running 2.2.6 (2022-02-04 17:00:38) with PHP 8.1.2 on Darwin / 19.6.0
Reading ./composer.json (/Users/cj/tmp/autoload/composer.json)
Loading config file /Users/cj/.composer/auth.json
Loading config file ./composer.json (/Users/cj/tmp/autoload/composer.json)
Checked CA file /usr/local/etc/ca-certificates/cert.pem: valid
Executing command (/Users/cj/tmp/autoload): git branch -a --no-color --no-abbrev -v
Executing command (/Users/cj/tmp/autoload): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/Users/cj/tmp/autoload): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/Users/cj/tmp/autoload): hg branch
Executing command (/Users/cj/tmp/autoload): fossil branch list
Executing command (/Users/cj/tmp/autoload): fossil tag list
Executing command (/Users/cj/tmp/autoload): svn info --xml
Reading /Users/cj/.composer/composer.json
Loading config file /Users/cj/.composer/auth.json
Loading config file /Users/cj/.composer/composer.json (/Users/cj/.composer/composer.json)
Loading config file /Users/cj/.composer/auth.json
Reading /Users/cj/.composer/auth.json
Reading /Users/cj/tmp/autoload/vendor/composer/installed.json
Reading /Users/cj/.composer/vendor/composer/installed.json
Generating optimized autoload files
Class App\Domain\Tasks\TaskStatus: located in ./app/Domain/Tasks/TaskStatus.php does not comply with psr-4 autoloading standard. Skipping.
Generated optimized autoload files containing 2 classes

And I expected this to happen:

I expected it to succeed, rather than fail on TaskStatus.php which is an Enum:

<?php
namespace App\Domain\Tasks;
Enum TaskStatus: string

If I remove (or set to false) the optimize-autoloader from the composer.json file, it works fine.

My guess: composer does not know how to optimize autoloading when Enums are present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions