Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize-autoloader fails with Enums #10521

Closed
cxj opened this issue Feb 7, 2022 · 2 comments
Closed

optimize-autoloader fails with Enums #10521

cxj opened this issue Feb 7, 2022 · 2 comments
Labels
Milestone

Comments

@cxj
Copy link

cxj commented Feb 7, 2022

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.

@Seldaek
Copy link
Member

Seldaek commented Feb 8, 2022

My guess from the excerpt of code you gave is this is caused by you using Enum instead of the expected enum keyword.

Should be an easy fix though, but you can use enum for now as workaround I believe.

@Seldaek Seldaek added this to the 2.2 milestone Feb 8, 2022
@Seldaek Seldaek added the Bug label Feb 8, 2022
@cxj
Copy link
Author

cxj commented Feb 8, 2022

Ah, right you are. I'm sorry I did not notice that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants