Class PHPStan\Type\VerbosityLevel

final

Controls the verbosity of type descriptions in error messages. When PHPStan describes a type for an error message, it uses VerbosityLevel to decide how much detail to include. Higher levels include more detail like constant values and array shapes. The four levels (from least to most verbose):

  • typeOnly: Just the type name, e.g. "string", "array", "Foo"
  • value: Includes constant values, e.g. "'hello'", "array{foo: int}", "non-empty-string"
  • precise: Maximum detail — adds subtracted types on object/mixed (e.g. "object~Bar"), lowercase/uppercase string distinctions, untruncated array shapes, and template type scope
  • cache: Internal level used for generating cache keys Used as a parameter to Type::describe() to control output detail: $type->describe(VerbosityLevel::typeOnly()) // "string" $type->describe(VerbosityLevel::value()) // "'hello'" $type->describe(VerbosityLevel::precise()) // "non-empty-lowercase-string" The getRecommendedLevelByType() factory method automatically chooses the right level for error messages based on what types are involved — it picks the minimum verbosity needed to distinguish the accepting type from the accepted type.
Methods