Skip to content

Absolute symlinks cause warnings for PSR-4 scanning #12478

@sanmai

Description

@sanmai
$ composer diagnose
Composer version: 2.8.10
PHP version: 8.4.8

Create a new project with:

{
    "name": "hello/hello",
    "autoload": {
        "psr-4": {
            "MyTools\\": "tools/"
        },
        "exclude-from-classmap": [
            "**/vendor/"
        ]
    }
}

Init another project inside the tools directory:

(mkdir -p tools; cd tools; composer init --name=hello/tools --require=phpunit/phpunit:^9 -n; composer install)

Dump the optimized autoloader:

$ composer dump-autoload -o
Generating optimized autoload files
Generated optimized autoload files containing 1 classes

So far so good, the vendor exclusion works as expected.

Now, move the tools directory somewhere else and create an absolute symlink to it:

mv tools/ /tmp/
ln -s /tmp/tools 

Dump the autoloader again:

composer dump-autoload -o

And observe an avalance of warnings:

Class PHPUnit\Framework\Exception located in ./tools/vendor/phpunit/phpunit/src/Framework/Exception/Exception.php does not comply with psr-4 autoloading standard (rule: MyTools\ => ./tools). Skipping.

Surprisingly, there is no such issue with relative symlinks:

mv tools tools2
ln -s tools2 tools
composer dump-autoload -o

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions