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

Generate metadata for factory method auto completion #36

Closed
axyr opened this issue Mar 28, 2016 · 15 comments
Closed

Generate metadata for factory method auto completion #36

axyr opened this issue Mar 28, 2016 · 15 comments

Comments

@axyr
Copy link
Contributor

axyr commented Mar 28, 2016

Currently methods like TextField::create(); does not 'resolve' to the TextField class but stays in Object.

Laravel as a great ide helper:
https://github.com/barryvdh/laravel-ide-helper
which generates a same kind of helper file.

PHPStorm documentation
https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata

I looked into this, but it is not as easy as it seems.

The problem is that Object::create(); uses get_called_class(); to get the class to generate.
If any has an idea to tackle this, I think this would be a great feature..

@axyr axyr changed the title Generate .phpstorm.meta.php for factory method auto completion Generate metadata for factory method auto completion Mar 28, 2016
@axyr
Copy link
Contributor Author

axyr commented Mar 28, 2016

Edited title to not only support phpstorm...

@Firesphere
Copy link
Member

Wouldn't this be more of something for the SSTemplate module, than in here?

@axyr
Copy link
Contributor Author

axyr commented Mar 28, 2016

Well. It bothers me and the purpose of this module is to support autocompletion. At least thats why I created this module...

So think it fits fine in here and once figured out how to map ClassName::create(); to ClassName the generation of the file should be fairly easy...

@axyr
Copy link
Contributor Author

axyr commented Mar 28, 2016

If we only had namespaces already... it would be much easier...

@Firesphere
Copy link
Member

Valid point :)

@Firesphere
Copy link
Member

I just tried one very risky method. Just because.

It's parsing the file, and prepends every ${something} = {ObjectThing}::create() with /** @var ObjectThing $something */\n To my surprise, it actually didn't destroy anything, but I am also very strongly AGAINST implementing something like this. It was a trial to see if the parsing of the file is possible 😉 not something to be taken serious. But at least parsing the files with a simple regex quickly, works quite fine!

@axyr
Copy link
Contributor Author

axyr commented Apr 14, 2016

I noticed that NetBeans has no problem with methods like TextField::create(...)->getMaxlength();

I use the /** @var .. */ etc as well, but it is pretty noisy if you ask me.

And for Form I never assign the Fields to a variable. Forms is where I have the most mess in PHPStorm...

I guess we should forget this for this module..

Or we need namespaces in SS or we need a PHPStorm build-in/plugin solution. Which I unfortunately do now know how to code...

@Firesphere
Copy link
Member

Well, namespacing will be done in 4, hopefully. But yeah, for PHPStorm, I think we'll have to fall back on the SilverStripe plugin.

@axyr
Copy link
Contributor Author

axyr commented Apr 15, 2016

Which only supports the template language...

@Firesphere
Copy link
Member

It actually does more, but was never renamed I think.

@axyr
Copy link
Contributor Author

axyr commented May 4, 2016

By not using create all the time, but just plain 'new ClassName', this is not a big problem...

I use create for all my forms, which makes them pretty ugly.

No, I favor code like this :

new FieldGroup(
    (new LimitedTextField('Zip', _t('Site.Zipcode', 'Zipcode')))
        ->addExtraClass('geocode'),
    (new LimitedTextField('City', _t('Site.City', 'City')))
        ->addExtraClass('geocode toggle')
)

Any reason why I 'should' use SomeClass::create instead?

@Firesphere
Copy link
Member

Firesphere commented May 4, 2016

Because create uses the Injector, which can return a spec faster. But that's all there is to it, I think.

There are more reasons probably. But the new statement works I guess.

@Firesphere
Copy link
Member

I still think though, supporting ::create() would be awesome.
But it's a minor issue and I would not think, it's part of what this module is trying to achieve.

@wernerkrauss
Copy link

FY(and others)I: the phpstorm plugin now manages ::create() autocompletion. See raket/idea-silverstripe#66

@axyr
Copy link
Contributor Author

axyr commented May 29, 2016

Thanks :)

Closed : use this https://github.com/raket/idea-silverstripe

@axyr axyr closed this as completed May 29, 2016
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

3 participants