Skip to content

Discovery: Composer TypeError on PSR-4 namespace prefixes with multiple lookup directories #2111

@nayleen

Description

@nayleen

Tempest version

3.0

PHP version

8.5

Operating system

Linux

Description

See Composer's schema regarding PSR-4 namespace registration: https://getcomposer.org/doc/04-schema.md#psr-4

If you need to search for a same prefix in multiple directories, you can specify them as an array as such:

{
    "autoload": {
        "psr-4": { "Monolog\\": ["src/", "lib/"] }
    }
}

The Composer class currently throws a TypeError in projects where a namespace prefix resides in multiple directories due to (what I understand to be) a wrong assumption about PSR-4 autoload paths:

->map(fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path))

TypeError: Tempest\Discovery\Composer::{closure:Tempest\Discovery\Composer::load():41}(): Argument #1 ($path) must be of type string, array given, called in /app/src/packages/support/src/Arr/functions.php on line 862

I've taken a step at a reproducing test and a fix in: #2112

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions