|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SzepeViktor\PHPStan\WordPress\Tests; |
| 6 | + |
| 7 | +use const ABSPATH; |
| 8 | +use const WP_CONTENT_DIR; |
| 9 | +use const WP_LANG_DIR; |
| 10 | +use const WPMU_PLUGIN_DIR; |
| 11 | +use const WP_PLUGIN_DIR; |
| 12 | +use const WP_DEBUG; |
| 13 | +use const WP_DEBUG_DISPLAY; |
| 14 | +use const EMPTY_TRASH_DAYS; |
| 15 | +use const SCRIPT_DEBUG; |
| 16 | +use const COOKIE_DOMAIN; |
| 17 | +use const WP_DEFAULT_THEME; |
| 18 | +use const MINUTE_IN_SECONDS; |
| 19 | +use const HOUR_IN_SECONDS; |
| 20 | +use const DAY_IN_SECONDS; |
| 21 | +use const WEEK_IN_SECONDS; |
| 22 | +use const MONTH_IN_SECONDS; |
| 23 | +use const YEAR_IN_SECONDS; |
| 24 | +use const KB_IN_BYTES; |
| 25 | +use const MB_IN_BYTES; |
| 26 | +use const GB_IN_BYTES; |
| 27 | +use const TB_IN_BYTES; |
| 28 | +use const PB_IN_BYTES; |
| 29 | +use const EB_IN_BYTES; |
| 30 | +use const OBJECT; |
| 31 | +use const OBJECT_K; |
| 32 | +use const ARRAY_A; |
| 33 | +use const ARRAY_N; |
| 34 | +use const EP_NONE; |
| 35 | +use const EP_PERMALINK; |
| 36 | +use const EP_ATTACHMENT; |
| 37 | +use const EP_DATE; |
| 38 | +use const EP_YEAR; |
| 39 | +use const EP_MONTH; |
| 40 | +use const EP_DAY; |
| 41 | +use const EP_ROOT; |
| 42 | +use const EP_COMMENTS; |
| 43 | +use const EP_SEARCH; |
| 44 | +use const EP_CATEGORIES; |
| 45 | +use const EP_TAGS; |
| 46 | +use const EP_AUTHORS; |
| 47 | +use const EP_PAGES; |
| 48 | +use const EP_ALL_ARCHIVES; |
| 49 | +use const EP_ALL; |
| 50 | +use const FS_CONNECT_TIMEOUT; |
| 51 | +use const FS_TIMEOUT; |
| 52 | +use const FS_CHMOD_DIR; |
| 53 | +use const FS_CHMOD_FILE; |
| 54 | + |
| 55 | +use function PHPStan\Testing\assertType; |
| 56 | + |
| 57 | +/* |
| 58 | + * Unconditional constants resolve to constant values and are |
| 59 | + * - defined in bootstrap.php |
| 60 | + * - NOT part of the dynamicConstantNames list in extension.neon. |
| 61 | + */ |
| 62 | + |
| 63 | +assertType('60', MINUTE_IN_SECONDS); |
| 64 | +assertType('3600', HOUR_IN_SECONDS); |
| 65 | +assertType('86400', DAY_IN_SECONDS); |
| 66 | +assertType('604800', WEEK_IN_SECONDS); |
| 67 | +assertType('2592000', MONTH_IN_SECONDS); |
| 68 | +assertType('31536000', YEAR_IN_SECONDS); |
| 69 | + |
| 70 | +assertType('1024', KB_IN_BYTES); |
| 71 | +assertType('1048576', MB_IN_BYTES); |
| 72 | +assertType('1073741824', GB_IN_BYTES); |
| 73 | + |
| 74 | +if (PHP_INT_SIZE === 8) { |
| 75 | + // 64bit |
| 76 | + assertType('1099511627776', TB_IN_BYTES); |
| 77 | + assertType('1125899906842624', PB_IN_BYTES); |
| 78 | + assertType('1152921504606846976', EB_IN_BYTES); |
| 79 | + // ZB_IN_BYTES and YB_IN_BYTES will be converted to floats. |
| 80 | +} |
| 81 | + |
| 82 | +assertType("'OBJECT'", OBJECT); |
| 83 | +assertType("'OBJECT_K'", OBJECT_K); |
| 84 | +assertType("'ARRAY_A'", ARRAY_A); |
| 85 | +assertType("'ARRAY_N'", ARRAY_N); |
| 86 | + |
| 87 | +assertType('0', EP_NONE); |
| 88 | +assertType('1', EP_PERMALINK); |
| 89 | +assertType('2', EP_ATTACHMENT); |
| 90 | +assertType('4', EP_DATE); |
| 91 | +assertType('8', EP_YEAR); |
| 92 | +assertType('16', EP_MONTH); |
| 93 | +assertType('32', EP_DAY); |
| 94 | +assertType('64', EP_ROOT); |
| 95 | +assertType('128', EP_COMMENTS); |
| 96 | +assertType('256', EP_SEARCH); |
| 97 | +assertType('512', EP_CATEGORIES); |
| 98 | +assertType('1024', EP_TAGS); |
| 99 | +assertType('2048', EP_AUTHORS); |
| 100 | +assertType('4096', EP_PAGES); |
| 101 | +assertType('3644', EP_ALL_ARCHIVES); |
| 102 | +assertType('8191', EP_ALL); |
| 103 | + |
| 104 | +/* |
| 105 | + * Conditional constants resolve to non constant types and are |
| 106 | + * - defined in bootstrap.php |
| 107 | + * - part of the dynamicConstantNames list in extension.neon. |
| 108 | + */ |
| 109 | + |
| 110 | +assertType('bool', WP_DEBUG); |
| 111 | +// assertType('bool|string', WP_DEBUG_LOG); // PHPStan does not yet support more than one type for constants |
| 112 | +assertType('bool', WP_DEBUG_DISPLAY); |
| 113 | + |
| 114 | +assertType('string', ABSPATH); |
| 115 | +assertType('string', WP_CONTENT_DIR); |
| 116 | +assertType('string', WP_PLUGIN_DIR); |
| 117 | +assertType('string', WPMU_PLUGIN_DIR); |
| 118 | +assertType('string', WP_LANG_DIR); |
| 119 | + |
| 120 | +assertType('int', FS_CONNECT_TIMEOUT); |
| 121 | +assertType('int', FS_TIMEOUT); |
| 122 | +assertType('int', FS_CHMOD_DIR); |
| 123 | +assertType('int', FS_CHMOD_FILE); |
| 124 | + |
| 125 | +assertType('string', COOKIE_DOMAIN); |
| 126 | +assertType('int', EMPTY_TRASH_DAYS); |
| 127 | +assertType('bool', SCRIPT_DEBUG); |
| 128 | +assertType('string', WP_DEFAULT_THEME); |
0 commit comments