forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic-constant.php
More file actions
45 lines (36 loc) · 1.51 KB
/
dynamic-constant.php
File metadata and controls
45 lines (36 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace DynamicConstants;
use function PHPStan\Testing\assertType;
define('GLOBAL_PURE_CONSTANT', 123);
define('GLOBAL_DYNAMIC_CONSTANT', false);
define('GLOBAL_DYNAMIC_CONSTANT_WITH_EXPLICIT_TYPES', null);
class DynamicConstantClass
{
const DYNAMIC_CONSTANT_IN_CLASS = 'abcdef';
const DYNAMIC_CONSTANT_WITH_EXPLICIT_TYPES_IN_CLASS = 'xyz';
const PURE_CONSTANT_IN_CLASS = 'abc123def';
/** @var string|null */
const DYNAMIC_NULL_WITH_PHPDOC_CONSTANT = null;
/** @var list<string> */
const DYNAMIC_EMPTY_ARRAY_WITH_PHPDOC_CONSTANT = [];
/** @var int */
const DYNAMIC_INCOMPATIBLE_PHPDOC_CONSTANT = null;
}
class NoDynamicConstantClass
{
// constant name is same as in DynamicConstantClass, just to test
const DYNAMIC_CONSTANT_IN_CLASS = 'xyz';
private function rip()
{
assertType('string', DynamicConstantClass::DYNAMIC_CONSTANT_IN_CLASS);
assertType('string|null', DynamicConstantClass::DYNAMIC_CONSTANT_WITH_EXPLICIT_TYPES_IN_CLASS);
assertType("'abc123def'", DynamicConstantClass::PURE_CONSTANT_IN_CLASS);
assertType("'xyz'", NoDynamicConstantClass::DYNAMIC_CONSTANT_IN_CLASS);
assertType('bool', GLOBAL_DYNAMIC_CONSTANT);
assertType('123', GLOBAL_PURE_CONSTANT);
assertType('string|null', GLOBAL_DYNAMIC_CONSTANT_WITH_EXPLICIT_TYPES);
assertType('string|null', DynamicConstantClass::DYNAMIC_NULL_WITH_PHPDOC_CONSTANT);
assertType('list<string>', DynamicConstantClass::DYNAMIC_EMPTY_ARRAY_WITH_PHPDOC_CONSTANT);
assertType('int', DynamicConstantClass::DYNAMIC_INCOMPATIBLE_PHPDOC_CONSTANT);
}
}