-
Notifications
You must be signed in to change notification settings - Fork 79
Allow to define if the type is an alias or not. #40
Conversation
src/Generator/ParameterGenerator.php
Outdated
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.
Instead of mixed, you could say array|string. That way we know exactly what the function is designed to consume
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.
I wouldn't allow array. Pass in a TypeGenerator if needed: arrays are squishy. Let's avoid stringly-typed and array-typed code ;-)
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.
Seconding @Ocramius ; looking through the method body, this would be far simpler if it accepts a type instance.
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.
Maybe an "AliasedType", with getOriginalType() and getAlias() methods.
|
@Ocramius Hello, I have made some modification regarding your feedback. Feel free for any more feedback. |
c58e978 to
57b8f04
Compare
|
@Ocramius Any news ? |
|
Feedback regarding the argument of the ParameterGenerator::setType method hasn't been addressed. Further complicated by weierophinney's remarks I think I would go for a string or TypeGenerator argument Additionally a test for the happy path and exception path should be added to 'test/Generator/ParameterGeneratorTest.php' . |
|
@basz thanks for your feedback! Is it really necessary to keep the string as argument of the ParameterGenerator::setType method. As @weierophinney said it will be more easy to pass only TypeGenerator object. I have refactored the code to use TypeGenerator class and string. |
|
I would say that would be better but is not possible without Breaking Compatibility. |
8f2d3a1 to
7da91f7
Compare
When a use statements is declared we should be able to use alias as type for parameters. This patch keep the current behavior and add a way to define if the parameter type is an alias or not.
Remove create type from array and add arguments to allow to use the type as alias. Fix Typo.
|
Hello, is there anyone who can tell me what is missing for this PR ? Thank you. |
|
I just went through this again, and I can't find a reason for the patch. What is the reasoning behind it? At least in generators, aliasing is actively harmful, and only causes confusion. @vonglasow where is this needed, exactly? |
|
@Ocramius hello, The goal was defined in this issue #37 to be short currently it's always a FQCN as type parameter. use Foo\Bar\SomeClass;
class GeneratedClass
{
public function generatedMethod(\Foo\Bar\SomeClass $instance) {
}
}and this PR allow to create code with using the implicit alias from use. use Foo\Bar\SomeClass;
class GeneratedClass
{
public function generatedMethod(SomeClass $instance) {
}
} |
|
Yes, that's what I don't understand: never had a need for aliasing in code If the final aim is to produce a "code beautifier, I would do so by On 20 Sep 2016 18:52, "vonglasow" notifications@github.com wrote:
|
|
Hello, sorry for the delay a lot of work. So, I don't understand your point. You mean you can arrived to the same results without allowing to use alias? The final aim for me was to produce a beautifier code but I don't know if it was the same goal for @postalservice14. If you can do it without using alias you can replace this PR by your own. But if the goal of @postalservice14 is to use alias as he wants, I think we need provide a way to do it but as you explain make it explicitly as not recommended. |
That's what this component is NOT for though. We actually moved to FQCNs-only because it was really messy to deal with aliases, since no contextual information is given to a type otherwise.
That's a good suggestion, but I'd still write a separate AST-based tool for transforming equivalent code then... |
|
Hello, what about this PR ? What do you need more ? |
|
To clarify, I'll put this in pseudo-code. Let's say we generate a class like following: namespace Foo;
use Bar\Baz;
class Taz
{
public function tab(Baz $baz) {
}
}Now, From a logical perspective, the generators used to create such a file are (pseudo-code - I don't remember the actual classes involved, just the rough structure): Now, the state of the This is a mess to deal with, especially if your code generation logic is local to a single method, and has no clue about the outer scope. This is the TL;DR why imported symbols in a code generator are messy as heck, and IMO shouldn't land in zend-code anymore (they were actually removed) |
|
I'm leaving this open to allow you to counter my argument, but this will likely not be merged, sorry :-( |
|
@Ocramius Ok, got your point. Don't be sorry, I understand ;) Thanks to take time to explain. |
When a use statements is declared we should be able to use alias as type
for parameters. This patch keep the current behavior and add a way to
define if the parameter type is an alias or not.