-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix Generator not generating namespaces to the written classes #98
Conversation
…ack argument so that the namespace gets generated and set correctly in every possible situation. Earlier way does work in the integration tests but for example in real life and in the in the examples/simple it fails to generate namespaces to the files
{ | ||
$printer = new PsrPrinter(); | ||
$phpNamespace = $classType->getNamespace(); | ||
$class = $printer->printClass($classType, $phpNamespace); | ||
|
||
$outputNamespace = (string) $phpNamespace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not rely on magic __toString()
.
{ | ||
$printer = new PsrPrinter(); | ||
$phpNamespace = $classType->getNamespace(); | ||
$class = $printer->printClass($classType, $phpNamespace); | ||
|
||
$outputNamespace = (string) $phpNamespace; | ||
if (empty(trim($outputNamespace))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compare with null
or ''
.
{ | ||
$printer = new PsrPrinter(); | ||
$phpNamespace = $classType->getNamespace(); | ||
$class = $printer->printClass($classType, $phpNamespace); | ||
|
||
$outputNamespace = (string) $phpNamespace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workaround needs a healthy, long code comment to explain its purpose.
I just experienced this issue in a project of mine as well after updating its dependencies with |
@spawnia Awesome that the real culprit was found, thank you 🤩 |
Hi,
Noticed with (tested with 0.29.2 and current master) that generating classes doesn't work correctly as it doesn't add namespaces as expected. When tested through
\Spawnia\Sailor\Tests\Integration\CodegenTest
they seem to be generated correctly but with the CLI command./vendor/bin/sailor
namespaces doesn't get added to the generated classes.This can be reproduced with
examples/simple
at least:With the changes in the PR, the simple example gets generated with the test.sh correctly and it also does work in the integration tests.
So I changed Generator::asPhpFile method to have additional namespace fallback argument so that the namespace gets generated and set correctly in every possible situation.
The original code works in the integration tests but for example in real life and in the in the
examples/simple
it fails to generate namespaces to the files.I haven't yet been able to pinpoint what causes the discrepancy between the integration tests and running the examples/tests manually but did notice the issue when trying to this package in a real world project.
Any ideas, how to trigger the situation in the tests? Will improve the PR if I can find way to reproduce it in the integration tests
Changes
Breaking changes