# Base PHPStan configuration for WordPress Core. # # This holds what PHPStan needs to know to analyze the WordPress codebase: the extensions for # WordPress-specific conventions, the paths analyzed and excluded, the supported PHP versions, # and the constants whose values vary. It rarely changes. # # The standards the code is held to, which are the rule level, the baselines, the errors # ignored as not actionable, and the strict rules enabled, are in phpstan.neon.dist instead, # so they can be read and reviewed apart from all of this. # # https://phpstan.org/config-reference services: # Bridges WordPress core's `@global Type $varname` function docblock convention to # PHPStan's variable type resolution. See tests/phpstan/GlobalDocBlockVisitor.php. - class: WordPress\PHPStan\GlobalDocBlockVisitor tags: - phpstan.parser.richParserNodeVisitor # Bridges WordPress core's hash notation, the nested `@type` list documenting the # contents of an array or object, to PHPStan's array and object shapes. # See tests/phpstan/HashNotationVisitor.php. - class: WordPress\PHPStan\HashNotationVisitor tags: - phpstan.parser.richParserNodeVisitor # Attaches the docblock documenting a hook to the hook's call, so that the return # type extension and the rules below can all read it. - class: WordPress\PHPStan\HookDocsVisitor tags: - phpstan.parser.richParserNodeVisitor # Resolves a hook call's documentation, whether written at the call or inherited # through the "This filter is documented in " convention. - class: WordPress\PHPStan\HookDocBlock # Types the return value of apply_filters() (and variants) from the `@param` type # documented for the value being filtered. Adapted from szepeviktor/phpstan-wordpress. - class: WordPress\PHPStan\ApplyFiltersDynamicFunctionReturnTypeExtension tags: - phpstan.broker.dynamicFunctionReturnTypeExtension # Enforces that every hook invocation is preceded by a documenting docblock or # a valid "This filter is documented in " reference comment. - class: WordPress\PHPStan\HookDocumentationRule tags: - phpstan.rules.rule # Enforces that a hook invocation passes as many arguments as its documentation # (inline or referenced) describes. - class: WordPress\PHPStan\HookParamCountRule tags: - phpstan.rules.rule # Runs the visitors above over every file PHPStan parses, not only the ones it # analyzes. # # `phpstan.parser.richParserNodeVisitor` is honored by PHPStan's RichParser, and # PathRoutingParser sends a file there only when it is one of the files being # analyzed. Everything else — a file merely read so that a function or class it # declares can be reflected — goes to the simple parser, which applies only the # name resolver. # # PHPStan can do that because its own two parsers agree about everything # reflection exposes: the simple one is wrapped in a CleaningParser, whose # CleaningVisitor empties function, method and closure bodies and touches nothing # else. Docblocks and signatures come out of either parser identically, so what is # reflected out of a file does not depend on whether that file was analyzed, and # the per-file reflection cache can be keyed on the file's contents alone. # # HashNotationVisitor breaks that agreement. It rewrites `@param`, `@return` and # `@var` docblocks, which are exactly what reflection exposes, so a file read # through the simple parser reflects the documented `array` where the same file # analyzed reflects the shape its hash notation describes. Analyzing a subset of # the tree then reports against types no longer derived, and writes that reading # into the shared cache for the next full run to restore. # # Wrapping the rich parser rather than the plain one restores the agreement: every # parse rewrites the same docblocks, the cleaning still happens on top, and the # reflection cache is keyed on contents correctly again. # # `currentPhpVersionSimpleParser` and `currentPhpVersionRichParser` are PHPStan's # own service names, from its conf/parsers.neon, and are not a documented extension # point. Should a future release rename either, this definition stops being wired # into anything and the behavior above returns; the errors it prevents are all of # the quiet sort, so check this first when a hash notation type looks wrong. # # `arguments!` replaces the inherited arguments rather than merging with them. # Without the `!`, the original `wrappedParser` argument survives and the container # fails to build with "Unknown named parameter $wrappedParser". currentPhpVersionSimpleParser: class: PHPStan\Parser\CleaningParser arguments!: wrappedParser: @currentPhpVersionRichParser autowired: false parameters: # Cache is stored locally, so it's available for CI. tmpDir: ../../.cache # Supported PHP versions. phpVersion: min: 70400 max: 80600 # If it's not enforced by PHP we can't assume users are passing valid values. treatPhpDocTypesAsCertain: false # These config options are explained in https://phpstan.org/config-reference checkFunctionNameCase: true inferPrivatePropertyTypeFromConstructor: true # Constants whose values may differ depending on the install. # # Each type is what core expects: the values core defines and documents, and that its reads are designed for. # Where sites, plugins, or themes are known to define wider values, a comment notes them. Many configs pass # getenv() through unconverted, which yields false when the variable is unset and otherwise a string (where # 'false' and 'off' are truthy). When core starts handling a value outside a type, widen the type along with it. dynamicConstantNames: ABSPATH: 'non-empty-string' ADMIN_COOKIE_PATH: 'string' ALLOW_SUBDIRECTORY_INSTALL: 'bool' AUTH_COOKIE: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. AUTH_KEY: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. AUTH_SALT: 'non-empty-string' # Also defined from getenv() strings, and as 'minor' (confused with WP_AUTO_UPDATE_CORE). Core checks truthiness. AUTOMATIC_UPDATER_DISABLED: 'bool' # Also defined as numeric strings from options, and as 0 or false, which turn off autosaves in the block editor. AUTOSAVE_INTERVAL: 'positive-int' BACKGROUND_COLOR: 'string' BACKGROUND_IMAGE: 'string' BLOGUPLOADDIR: 'non-empty-string' # Core defined false before r58011, and many configs still do. setcookie() treats it like ''. COOKIE_DOMAIN: 'string' # Raw getenv() configs also yield false when unset. Core only concatenates it, so false acts like ''. COOKIEHASH: 'string' COOKIEPATH: 'string' CUSTOM_TAGS: 'bool' # Raw getenv() configs also yield false. Core treats any falsy value as empty. DB_COLLATE: 'string' # Also defined as 1, 'true', and getenv() strings. Core checks truthiness. DISALLOW_FILE_EDIT: 'bool' DISALLOW_UNFILTERED_HTML: 'bool' # Some plugins define 1. Core checks truthiness. DOING_AJAX: 'bool' # Some plugins define 1. Core checks truthiness. DOING_CRON: 'bool' # Also defined as false (treated like 0), -1, and getenv() strings. Where core multiplies it by DAY_IN_SECONDS, # an empty string fatals on PHP 8 (on PHP 7.4 it acts like 0), and a negative number makes wp_scheduled_delete() # purge all trash. EMPTY_TRASH_DAYS: 'non-negative-int' # Also defined as getenv() strings. force_ssl_admin() casts it with (bool). FORCE_SSL_ADMIN: 'bool' FORCE_SSL_LOGIN: 'bool' FS_CHMOD_DIR: 'int' FS_CHMOD_FILE: 'int' # Also defined as numeric strings from options. On PHP 8, ftp_connect() throws for a value below 1. FS_CONNECT_TIMEOUT: 'positive-int' FS_TIMEOUT: 'positive-int' HEADER_IMAGE: 'string' # Some legacy themes define a numeric string, such as '200'. Core casts it with (int). HEADER_IMAGE_HEIGHT: 'int' # Some legacy themes define a numeric string, such as '940'. Core casts it with (int). HEADER_IMAGE_WIDTH: 'int' HEADER_TEXTCOLOR: 'string' LOGGED_IN_COOKIE: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. LOGGED_IN_KEY: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. LOGGED_IN_SALT: 'non-empty-string' MEDIA_TRASH: 'bool' # Configs generated by some backup plugins define 1 or '1'. Core checks truthiness. MULTISITE: 'bool' MUPLUGINDIR: 'non-empty-string' NO_HEADER_TEXT: 'bool' # The WordPress MU sample config defined '', which disables the 404 redirect, but for an unknown site on a # subdomain network core then sends an empty Location header. NOBLOGREDIRECT: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. NONCE_KEY: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. NONCE_SALT: 'non-empty-string' PASS_COOKIE: 'non-empty-string' PLUGINDIR: 'non-empty-string' PLUGINS_COOKIE_PATH: 'string' RECOVERY_MODE_COOKIE: 'non-empty-string' REST_REQUEST: 'bool' # Also defined as 1 or 0, and as getenv() strings. Core checks truthiness. SAVEQUERIES: 'bool' # Also defined as getenv() strings. Core checks truthiness. SCRIPT_DEBUG: 'bool' SECRET_KEY: 'non-empty-string' SECRET_SALT: 'non-empty-string' SECURE_AUTH_COOKIE: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. SECURE_AUTH_KEY: 'non-empty-string' # Some configs define '', and ones that read environment variables also yield false or null when unset. Core # treats a falsy value as missing. SECURE_AUTH_SALT: 'non-empty-string' # Some code defines 1 or 'true'. Core checks truthiness. SHORTINIT: 'bool' SITECOOKIEPATH: 'string' STYLESHEETPATH: 'string' TEMPLATEPATH: 'string' TEST_COOKIE: 'non-empty-string' UPLOADBLOGSDIR: 'non-empty-string' USER_COOKIE: 'non-empty-string' WP_ALLOW_MULTISITE: 'bool' WP_CACHE: 'bool' # Raw getenv() configs also yield false, which core concatenates as '', so that plugins load from /plugins. WP_CONTENT_DIR: 'non-empty-string' WP_CONTENT_URL: 'non-empty-string' WP_CRON_LOCK_TIMEOUT: 'positive-int' # Also defined as 0 or 1, and as getenv() strings. Core checks truthiness. WP_DEBUG: 'bool' # Also defined as 0, and as getenv() strings. Core checks truthiness, and null leaves display_errors as is. WP_DEBUG_DISPLAY: 'bool|null' # A bool or a log file path. getenv() configs also define '' or '0' (both disable logging) and 'false' (logs # to a file named "false"). WP_DEBUG_LOG: 'bool|non-falsy-string' # getenv() configs also yield '' or false, for which wp_get_theme() returns the active theme instead. WP_DEFAULT_THEME: 'non-empty-string' # Some sites define true. wp_get_development_mode() treats an unknown value as '', but Site Health shows it as is. WP_DEVELOPMENT_MODE: '''core''|''plugin''|''theme''|''all''|''''' WP_INSTALLING: 'bool' WP_INSTALLING_NETWORK: 'bool' WP_LANG_DIR: 'non-empty-string' WP_MAX_MEMORY_LIMIT: 'string' WP_MEMORY_LIMIT: 'string' WP_NETWORK_ADMIN: 'bool' WP_PLUGIN_DIR: 'non-empty-string' WP_PLUGIN_URL: 'non-empty-string' # Also defined as numeric strings, from options or getenv(). Core casts with (int). WP_POST_REVISIONS: 'bool|int' WP_REPAIRING: 'bool' WP_RUN_CORE_TESTS: 'bool' # Raw getenv() configs also yield false when unset. WP_SITEURL: 'string' WP_START_TIMESTAMP: 'float' # Some code defines 0, or the string 'false' (which core treats as true). WP_USE_THEMES: 'bool' WP_USER_ADMIN: 'bool' WPLANG: 'string' WPMU_ACCEL_REDIRECT: 'bool' WPMU_PLUGIN_DIR: 'non-empty-string' WPMU_PLUGIN_URL: 'non-empty-string' WPMU_SENDFILE: 'bool' # Some plugins define 1. Core checks truthiness. XMLRPC_REQUEST: 'bool' # What directories and files should be scanned. paths: - ../../src/wp-admin - ../../src/wp-includes - ../../src/wp-content/themes/ipsum - ../../src/wp-content/themes/twentyeleven - ../../src/wp-content/themes/twentyfifteen - ../../src/wp-content/themes/twentyfourteen - ../../src/wp-content/themes/twentynineteen - ../../src/wp-content/themes/twentyseventeen - ../../src/wp-content/themes/twentysixteen - ../../src/wp-content/themes/twentyten - ../../src/wp-content/themes/twentythirteen - ../../src/wp-content/themes/twentytwelve - ../../src/wp-content/themes/twentytwenty - ../../src/wp-content/themes/twentytwentyfive - ../../src/wp-content/themes/twentytwentyfour - ../../src/wp-content/themes/twentytwentyone - ../../src/wp-content/themes/twentytwentythree - ../../src/wp-content/themes/twentytwentytwo - ../../src/index.php - ../../src/wp-activate.php - ../../src/wp-blog-header.php - ../../src/wp-comments-post.php - ../../src/wp-cron.php - ../../src/wp-links-opml.php - ../../src/wp-load.php - ../../src/wp-login.php - ../../src/wp-mail.php - ../../src/wp-settings.php - ../../src/wp-signup.php - ../../src/wp-trackback.php - ../../src/xmlrpc.php - GlobalDocBlockVisitor.php - HashEntry.php - HashNotationVisitor.php - HookDocsVisitor.php - HookDocBlock.php - ApplyFiltersDynamicFunctionReturnTypeExtension.php - HookDocumentationRule.php - HookParamCountRule.php bootstrapFiles: - bootstrap.php scanFiles: - ../../wp-config-sample.php - ../../src/wp-admin/includes/ms.php excludePaths: analyseAndScan: # Locally installed npm dependencies, such as in bundled themes, which may include PHP files. - */node_modules/* # Composer dependencies of themes and plugins, which are not part of core. - ../../src/wp-content/*/vendor/* analyse: # These files are deprecated. - ../../src/wp-admin/includes/deprecated.php - ../../src/wp-admin/includes/ms-deprecated.php - ../../src/wp-includes/deprecated.php - ../../src/wp-includes/ms-deprecated.php - ../../src/wp-includes/pluggable-deprecated.php # These files are autogenerated by tools/gutenberg/copy.js. - ../../src/wp-includes/blocks # Generated output from the Gutenberg plugin's wp-build templates. - ../../src/wp-includes/build # Third-party libraries. - ../../src/wp-admin/includes/class-ftp-pure.php - ../../src/wp-admin/includes/class-ftp-sockets.php - ../../src/wp-admin/includes/class-ftp.php - ../../src/wp-admin/includes/class-pclzip.php - ../../src/wp-includes/ID3 - ../../src/wp-includes/IXR - ../../src/wp-includes/PHPMailer - ../../src/wp-includes/Requests - ../../src/wp-includes/SimplePie - ../../src/wp-includes/Text - ../../src/wp-includes/atomlib.php - ../../src/wp-includes/class-IXR.php - ../../src/wp-includes/class-avif-info.php - ../../src/wp-includes/class-json.php - ../../src/wp-includes/class-phpass.php - ../../src/wp-includes/class-pop3.php - ../../src/wp-includes/class-requests.php - ../../src/wp-includes/class-simplepie.php - ../../src/wp-includes/class-snoopy.php - ../../src/wp-includes/class-wp-feed-cache.php - ../../src/wp-includes/class-wp-http-ixr-client.php - ../../src/wp-includes/class-wp-http-requests-hooks.php - ../../src/wp-includes/class-wp-http-requests-response.php - ../../src/wp-includes/class-wp-simplepie-file.php - ../../src/wp-includes/class-wp-simplepie-sanitize-kses.php - ../../src/wp-includes/class-wp-text-diff-renderer-inline.php - ../../src/wp-includes/class-wp-text-diff-renderer-table.php - ../../src/wp-includes/php-ai-client - ../../src/wp-includes/pomo - ../../src/wp-includes/rss.php - ../../src/wp-includes/sodium_compat # No global `typeAliases` are defined here, since docblocks in src/ that use them are not # self-contained: the aliases are lost from the stubs generated from core, and anyone who # analyzes against core would have to define each one. Declare an alias with `@phpstan-type` # on a class, and import it with `@phpstan-import-type` into other classes, instead. A type # used by functions has to be repeated until PHPStan supports declaring an alias with # `@phpstan-type` outside a class: https://github.com/phpstan/phpstan/issues/9164