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

Create phpDoc @method for "create" on all Injectables #8660

Closed
JorisDebonnet opened this issue Dec 9, 2018 · 4 comments
Closed

Create phpDoc @method for "create" on all Injectables #8660

JorisDebonnet opened this issue Dec 9, 2018 · 4 comments

Comments

@JorisDebonnet
Copy link
Contributor

Any classes implementing Injectable should have a @method phpDoc annotation for the create method to have a better experience in IDEs. Because right now, it just says "any number of arguments".

Example for SilverStripe\Forms\TextField:

/**
 * Text input field.
 *
 * @method static TextField create(string $name, null|string $title = null, string $value = '', null|int $maxLength = null, null|Form $form = null)
 */
class TextField extends FormField

The signatures are taken from the constructors and their phpDoc annotations. This way, you get the exact same IDE help for the ::create() method as for the constructor, which can make the adoption of the Factory method easier.

Technically, it could be possible to automate this across all files with some script, but I'm not sure that would be faster than manually doing it... Depends on how many classes actually use Injectable, I guess. If some modules do as well, it might be useful to write such a script.

@chillu
Copy link
Member

chillu commented Dec 11, 2018

Didn't know that worked, good stuff! Do you want to do a PR for core modules on this? There's a module out there which auto-adds some PHPDoc to custom SilverStripe code (e.g. getters for $db), but I can't remember what it was called. If you track that down, maybe suggest to add it there?

I don't think anyone will object to doing this, but it's unlikely to be actioned by the core team. So I'll put a feedback-required/author on here, up to you to send a PR - otherwise I'll come across this again in a few months and will close ;)

@ScopeyNZ
Copy link
Contributor

Adds to list of hackday ideas

@robbieaverill
Copy link
Contributor

Related issue thread on the IDE annotator module: silverleague/silverstripe-ideannotator#113

@GuySartorelli
Copy link
Member

Looks like chillu forgot to close this. It's a good idea but I don't think having an issue open for this is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants