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

Why NoInlineVarDocs? #108

Closed
amrdoe opened this issue Oct 11, 2019 · 5 comments
Closed

Why NoInlineVarDocs? #108

amrdoe opened this issue Oct 11, 2019 · 5 comments

Comments

@amrdoe
Copy link

amrdoe commented Oct 11, 2019

What is the problem with having type hinting for vars, and is there an alternative way to type hint vars?

@mattstauffer
Copy link
Member

This is purely my preference that I've forced on everyone else at Tighten: I don't like code that purely serves IDEs, and that's what those inline doc blocks do.

@amrdoe
Copy link
Author

amrdoe commented Oct 11, 2019

Well while I agree with you at this point, as they make the code bulky and a bit messy. But in the mean time php is not providing a proper way to type hint variables. And it is important for third party packages to have type hinting to help the users to know what is the expected type for the variable without having to read the source code to know/guess. Plus some classes may need to use getters/setters like for example Eloquent models. you may want to type hint attributes to make others aware of what fields are in the corresponding table and what types are them without having to access to or review the database schema.

@amrdoe amrdoe changed the title Why is NoInlineVarDocs? Why NoInlineVarDocs? Oct 11, 2019
@mattstauffer
Copy link
Member

So, in case it's not clear, tlint is very opinionated. It's almost guaranteed that there are people who are going to disagree with some of its linters, which is why they can all be disabled one-by-one.

In case it's not clear, it's entirely possible to type hint variables; you just can't use docblocks to document types.

I certainly understand the circumstances that would merit this, and even within Tighten, if we had a project or a package that needed those, I'd say "just disable this Linter for that project." These aren't universal rules; they're our best-and-preferred practices for 90% of the code we write.

@amrdoe
Copy link
Author

amrdoe commented Oct 11, 2019

Ok now I get it so about this

In case it's not clear, it's entirely possible to type hint variables; you just can't use docblocks to document types.

What is the other way to do it that is allowed by Tighten Lint?

@mattstauffer
Copy link
Member

public function doThing(Thing $thing)
{
    // This is allowed
}
public function doThing(Thing $thing)
{
    /** @var ThingCollection */
    $things = $this->thingRepository->getThingsByThing($thing);
    // This is not allowed ^^
}

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

3 participants