Skip to content

Stubs for WordPress functions and classes to be used with phan

License

Notifications You must be signed in to change notification settings

skaut/wordpress-stubs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

High quality stubs for WordPress

Packagist Version GitHub Actions Workflow Status Packagist Downloads Packagist License Packagist Dependency Version

This repo contains stubs for WordPress functions and classes to be used with phan or phpstan. This allows for better type-checking of a codebase as the stubs all have type information.

Alternatives

The php-stubs/wordpress-stubs project uses stubs that are exported directly from WordPress source code. That means that the stubs are more complete and updated quicker. On the other hand, a lot of functions and classes are documented poorly in WordPress and array types are almost never typed properly (i. e. just array<mixed>). This package has all the stubs created by hand, so they are much more precise.

Installation

$ composer require --dev skaut/wordpress-stubs

Add to your .phan/config.php:

return [
	'directory_list' => [
		'vendor/skaut/wordpress-stubs/stubs'
	],
	'exclude_analysis_directory_list' => [
		'vendor/skaut/wordpress-stubs/stubs'
	]
];

Add to your phpstan.neon:

parameters:
	scanDirectories:
	  - vendor/skaut/wordpress-stubs/stubs
	scanFiles:
	  - vendor/skaut/wordpress-stubs/stubs/WordPress/functions.php
	dynamicConstantNames:
	  - WP_DEBUG
	  - ...

(you have to list dynamic constants yourself)

Completeness

The stubs are not complete. If you spot any missing functions or classes, please open an issue.