-
Notifications
You must be signed in to change notification settings - Fork 34
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
Comments
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. |
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. |
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. |
Ok now I get it so about this
What is the other way to do it that is allowed by Tighten Lint? |
public function doThing(Thing $thing)
{
// This is allowed
} public function doThing(Thing $thing)
{
/** @var ThingCollection */
$things = $this->thingRepository->getThingsByThing($thing);
// This is not allowed ^^
} |
What is the problem with having type hinting for vars, and is there an alternative way to type hint vars?
The text was updated successfully, but these errors were encountered: