You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Symfony Maker bundle decides the path where it creates files by transforming namespaces (given by the individual makers) to file paths, given the composer autloading configuration. This transformation is not always possible unabigiously.
The code that transforms namespaces to directories currently resides here.
In cases where a namespace can't be resolved to a unique path, it just picks the "first" possible path (whatever this means, as JSON object keys, such as the "autoload" key inside the composer.json, are by definition unordered).
This means that it is not possible to generate files in directories outside this "first match" autoload path.
For example
If you configure your test cases to live in the same namespaces as the classes they test (useful to test classes that are @psalm-internal, and generally to reduce use statements), but in a separate directory (useful for tools like the composer-require-checker), you might have an autoload configuration like the following:
I could think of the following ways to solve this:
Interactive selection
PHPStorm provides an interactive selection when moving a class to a namespace and the path is ambigious. A maker command can't spawn a window, but it could use an interactive CLI:
Path for /App/AcmeFactory:
[0] src/App/AcmeFactory.php
[1] tests/App/AcmeFactory.php
>
It seems like this needs to be explicitly supported by the make commands – either by calling a function, which gets an Output passed and checks the namespace for ambiguosity and does the prompt in case, or by calling that function when handling an exception that AutoloaderUtil would throw, or by passing the Output down to the FileManager/AutoloaderUtil.
Provide a way to hard-overwrite the path
Calling a maker command with --target-directory=tests/App/Acme could ignore the namespace and hardly create the file in tests/App/Acme(maybe throw in error if this doesn't make sense given the namespace).
This would be much harder to use, but easier to implement, as we wouldn't need to pass an Output to the AutoloaderUtil or a similar function.
However, it still needs explicit support by the make commands, as they need to catch that parameter and add its content to the ClassNameDetails.
The Symfony Maker bundle decides the path where it creates files by transforming namespaces (given by the individual makers) to file paths, given the composer autloading configuration. This transformation is not always possible unabigiously.
The code that transforms namespaces to directories currently resides here.
In cases where a namespace can't be resolved to a unique path, it just picks the "first" possible path (whatever this means, as JSON object keys, such as the
"autoload"
key inside thecomposer.json
, are by definition unordered).This means that it is not possible to generate files in directories outside this "first match" autoload path.
For example
If you configure your test cases to live in the same namespaces as the classes they test (useful to test classes that are
@psalm-internal
, and generally to reduceuse
statements), but in a separate directory (useful for tools like thecomposer-require-checker
), you might have an autoload configuration like the following:In this case, it is not possible to create files in the
tests
directory using MakerBundle.The text was updated successfully, but these errors were encountered: