Since: 8.0

class ExpectedValues (View source)

The attribute specifies the expected values of an entity: return values for functions and arguments' values for methods.

If the attribute is applied, PhpStorm assumes that only the arguments specified in the attribute constructor can be passed/returned. This will affect the following:

  • Code completion - expected arguments are displayed on the top of the suggestions list when used in comparison expressions
  • Inspections [when used in a comparison with a value/assignment to/return from method] - the element absent from the expected values list produces the inspection warning
  • Code generation - for example, when generating the 'switch' statement, all possible expected values are inserted automatically

Expected values can be any of the following:

  • numbers
  • string literals
  • constant references
  • class constant references

Expected arguments can be specified in any of the following ways:

  • #[ExpectedValues(values: [1,2,3])] means that one of the following is expected: `1`, `2`, or `3`
  • #[ExpectedValues(values: MY_CONST] - default value of MY_CONST is expected to be array creation expression, in this case value of MY_CONST will be inlined
  • #[ExpectedValues(flags: [1,2,3])] means that a bitmask of the following is expected: `1`, `2`, or `3`
  • #[ExpectedValues(valuesFromClass: MyClass::class)] means that one of the constants from the class `MyClass` is expected
  • #[ExpectedValues(flagsFromClass: ExpectedValues::class)] means that a bitmask of the constants from the class `MyClass` is expected

The attribute with the number of provided constructor arguments different from 1 will result in undefined behavior.

Methods

__construct(array $values = [], array $flags = [], string|null $valuesFromClass = null, string|null $flagsFromClass = null)

No description

Details

__construct(array $values = [], array $flags = [], string|null $valuesFromClass = null, string|null $flagsFromClass = null)

No description

Parameters

array $values
array $flags
string|null $valuesFromClass
string|null $flagsFromClass