Description
Currently, PHPantom does not treat calling methods that do not exist as errors:
This means the editor is not aware of hard errors, "hard" as in "it will throw an syntax exception you like or not".
Use case
Basically this allows the developer to immediately pick typos on method and properties while writing instead of waiting for the error to happen.
Proposed solution
Throw an error if the method or property does not exist.
This should not be an error depending on the call:
- If the class implements
__call, method calls should not show an error.
- If the class implements
__callStatic, static method calls should not show an error.
- If the class implements
__get, dynamic property getters should not show an error.
For Laravel and other frameworks, properties set/get is pure magic. This should be detected using the following list, in order of importance:
- PHPDoc (primary source of truth): The developer says what the model has. Include traits/extended as fallback.
- Casts: It states the property AND type.
- Attributes: Manually states the property and type, even if these are virtual. Also include traits that use
mergeCasts() on initialize{TraitName}.
- Fillable/Hidden + Migration: mixes the property and the type. Also include traits that use
mergeFillable() and mergeHidden() on initialize{TraitName}.
- Relationship property: Map a Model to the property (Laravel magic). Don't use
TModel|null unless the dev explicitly says so via PHPDoc. Include Traits
- Local Scopes: states the method, and attributes. Include Traits with scopes.
- Magic Local Scopes: Typical
where + {tableColumn} + params..., like wherePublishedAt(null).
It's kind of a hassle, but the only way to offer code completion in a reliable way for models.
Alternatives considered
Going back to PHPStorm?
Code example
Description
Currently, PHPantom does not treat calling methods that do not exist as errors:
This means the editor is not aware of hard errors, "hard" as in "it will throw an syntax exception you like or not".
Use case
Basically this allows the developer to immediately pick typos on method and properties while writing instead of waiting for the error to happen.
Proposed solution
Throw an error if the method or property does not exist.
This should not be an error depending on the call:
__call, method calls should not show an error.__callStatic, static method calls should not show an error.__get, dynamic property getters should not show an error.For Laravel and other frameworks, properties set/get is pure magic. This should be detected using the following list, in order of importance:
mergeCasts()oninitialize{TraitName}.mergeFillable()andmergeHidden()oninitialize{TraitName}.TModel|nullunless the dev explicitly says so via PHPDoc. Include Traitswhere+{tableColumn}+params..., likewherePublishedAt(null).It's kind of a hassle, but the only way to offer code completion in a reliable way for models.
Alternatives considered
Going back to PHPStorm?
Code example