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

Strauss Fail when a namespace is mapped to an array of paths #76

Closed
TheTBO opened this issue Oct 24, 2023 · 6 comments
Closed

Strauss Fail when a namespace is mapped to an array of paths #76

TheTBO opened this issue Oct 24, 2023 · 6 comments

Comments

@TheTBO
Copy link

TheTBO commented Oct 24, 2023

when multiple directories are add for the same namespace as specified in Composer documentaion:

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

it results in the error:

PHP Fatal error:  Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in [REDACTED]/vendor/brianhenryie/strauss/src/Composer/Extra/StraussConfig.php:235

it seems like the problem is strauss always expect the configuration to be a string and try to trim() it.

@BrianHenryIE
Copy link
Owner

Weird, that should be fixed already #37 35d0043. I'll take another look soon.

I think as a workaround this might work:

  "extra": {
        "strauss": {
            "override_autoload": {
                "monolog/monolog": {
                    "classmap": ["src/", "lib/"]
                }
            },

@TheTBO
Copy link
Author

TheTBO commented Oct 25, 2023

Thank you for the workaround.
Sorry but I'm a bit confused, the commit is about the FileEnumerator class which is not being used in StraussConfig constructor where the error happen

            // Check each autoloader.
            foreach ($composer->getPackage()->getAutoload() as $autoload) {
                // To see if one of its paths.
                foreach ($autoload as $path) {
                    // Matches the target directory.
                    if (trim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR === $this->getTargetDirectory()) {
                        $this->classmapOutput = false;
                        break 2;
                    }
                }
            }

Furthermore, the test case doesn't seem to include PSR-0/PSR-4 config at all.

EDIT: using the workaround still result in the same error.
EDIT2: my bad I misunderstood how the workaround should work, I guess you set the array only in extra.strauss not autoload.PSR-#

@BrianHenryIE
Copy link
Owner

BrianHenryIE commented Oct 26, 2023

Can you give me an actual broken composer.json. I've tried writing tests with the example you gave me and they're passing. I can see that it should fail in the code you highlighted, but I want a test!

@TheTBO
Copy link
Author

TheTBO commented Oct 29, 2023

Sure, here composer.json
it's a modified version from fakerpress

@BrianHenryIE
Copy link
Owner

This should be fixed in master now. See: b32fe49

@TheTBO
Copy link
Author

TheTBO commented Oct 31, 2023

Great, It works flawlessly now.
Thank you very much.

@TheTBO TheTBO closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants