ExpectedValues.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace JetBrains\PhpStorm;
  3. use Attribute;
  4. /**
  5. * The attribute specifies the expected values of an entity: return values for functions and arguments' values for methods.
  6. *
  7. * If the attribute is applied, PhpStorm assumes that only the arguments specified in the attribute constructor can
  8. * be passed/returned. This will affect the following:
  9. * <ul>
  10. * <li><i>Code completion</i> - expected arguments are displayed on the top of the suggestions list when used in comparison expressions</li>
  11. * <li><i>Inspections [when used in a comparison with a value/assignment to/return from method]</i> - the element absent from the expected values list produces the inspection warning</li>
  12. * <li><i>Code generation</i> - for example, when generating the 'switch' statement, all possible expected values are inserted automatically</li>
  13. * </ul>
  14. *
  15. * Expected values can be any of the following:
  16. * <ul>
  17. * <li>numbers</li>
  18. * <li>string literals</li>
  19. * <li>constant references</li>
  20. * <li>class constant references</li>
  21. * </ul>
  22. *
  23. * Expected arguments can be specified in any of the following ways:
  24. * <ul>
  25. * <li><b>#[ExpectedValues(values: [1,2,3])]</b> means that one of the following is expected: `1`, `2`, or `3`</li>
  26. * <li><b>#[ExpectedValues(values: MY_CONST]</b> - default value of MY_CONST is expected to be array creation expression, in this case value of MY_CONST will be inlined</li>
  27. * <li><b>#[ExpectedValues(flags: [1,2,3])]</b> means that a bitmask of the following is expected: `1`, `2`, or `3`</li>
  28. * <li><b>#[ExpectedValues(valuesFromClass: MyClass::class)]</b> means that one of the constants from the class `MyClass` is expected</li>
  29. * <li><b>#[ExpectedValues(flagsFromClass: ExpectedValues::class)]</b> means that a bitmask of the constants from the class `MyClass` is expected</li>
  30. * </ul>
  31. *
  32. * The attribute with the number of provided constructor arguments different from 1 will result in undefined behavior.
  33. * @since 8.0
  34. */
  35. #[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)]
  36. class ExpectedValues {
  37. public function __construct(array $values = [], array $flags = [], string $valuesFromClass = null, string $flagsFromClass = null)
  38. {
  39. }
  40. }