IModel
extends
IConstraint
in
Parent interface for all type models.
A type model is a class that model data, i.e. it defines a set of allowed PHP values.
Implementation instances provide constraints that define what value is acceptable or not.
This interface is implemented by all type models (either directly or through another interface). This makes typing a type model possible (for instance, as a function parameter). All implementing, non-abstract classes are final. This ensures a type model is exactly one (and not zero or more than one) type model. PHPStan ensures classes are final.
Using a separate class for each type makes it possible to type the functions and to return constraints of the corresponding type only in getConstraints().
Another way would be to only use the IScalarModel and the IEntity interfaces. There would then be a ScalarModel class with a getType() method returning a Type enum, reducing the number of classes and interfaces, and also forcing one and only one type for each model. However, this would mean that there wouldn’t be static typing for constraints.
Using classes instead of, say, a method that returns an enum, will 1) make it possible to add new classes without modifying said enum and 2) will make sure a model cannot change its type and 3) provide typed constraints.
Tags
Table of Contents
Methods
- getNotNullConstraint() : INotNullConstraint|null
- isNullable() : bool
- Shorter way to check whether the content can be null.
Methods
getNotNullConstraint()
public
getNotNullConstraint() : INotNullConstraint|null
Return values
INotNullConstraint|null —Whether the content is necessarily specified or can be left omitted.
isNullable()
Shorter way to check whether the content can be null.
public
isNullable() : bool