{"id":13490148,"url":"https://github.com/szepeviktor/phpstan-wordpress","last_synced_at":"2025-04-12T20:38:32.591Z","repository":{"id":37413062,"uuid":"184879329","full_name":"szepeviktor/phpstan-wordpress","owner":"szepeviktor","description":"WordPress extensions for PHPStan ⛏️","archived":false,"fork":false,"pushed_at":"2025-02-12T18:43:37.000Z","size":438,"stargazers_count":282,"open_issues_count":13,"forks_count":26,"subscribers_count":12,"default_branch":"2.x","last_synced_at":"2025-04-05T19:06:56.918Z","etag":null,"topics":["phpstan","phpstan-extension","static-analysis","wordpress"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/szepeviktor/phpstan-wordpress","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/szepeviktor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"szepeviktor","custom":"https://www.paypal.me/szepeviktor"}},"created_at":"2019-05-04T10:09:51.000Z","updated_at":"2025-03-30T00:45:38.000Z","dependencies_parsed_at":"2022-08-02T11:53:16.169Z","dependency_job_id":"fc59ea50-1bd9-4af7-9fa9-3d613e4c2db9","html_url":"https://github.com/szepeviktor/phpstan-wordpress","commit_stats":{"total_commits":387,"total_committers":15,"mean_commits":25.8,"dds":0.5400516795865633,"last_synced_commit":"22aaab0e052ca496868cd98ce4ea40b20f5e7061"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szepeviktor%2Fphpstan-wordpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szepeviktor%2Fphpstan-wordpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szepeviktor%2Fphpstan-wordpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szepeviktor%2Fphpstan-wordpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szepeviktor","download_url":"https://codeload.github.com/szepeviktor/phpstan-wordpress/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631668,"owners_count":21136554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["phpstan","phpstan-extension","static-analysis","wordpress"],"created_at":"2024-07-31T19:00:41.590Z","updated_at":"2025-04-12T20:38:32.568Z","avatar_url":"https://github.com/szepeviktor.png","language":"PHP","funding_links":["https://github.com/sponsors/szepeviktor","https://www.paypal.me/szepeviktor"],"categories":["PHP"],"sub_categories":[],"readme":"\u003e [!IMPORTANT]\n\u003e Hello everyone! This is Viktor who runs this PHPStan extension. I am planning to stop contributing to the WordPress ecosystem because it is extremely difficult and no one asks me **to join his team** as I am a thinker, a devops person, a tool maker (not a builder).\n\nPlease support my work to avoid abandoning this package.\n\n[![Sponsor](https://github.com/szepeviktor/.github/raw/master/.github/assets/github-like-sponsor-button.svg)](https://github.com/sponsors/szepeviktor)\n\nThank you!\n\n# WordPress Extensions for PHPStan\n\n[![Packagist stats](https://img.shields.io/packagist/dt/szepeviktor/phpstan-wordpress.svg)](https://packagist.org/packages/szepeviktor/phpstan-wordpress/stats)\n[![Packagist](https://img.shields.io/packagist/v/szepeviktor/phpstan-wordpress.svg?color=239922\u0026style=popout)](https://packagist.org/packages/szepeviktor/phpstan-wordpress)\n[![Tweet](https://img.shields.io/badge/Tweet-share-d5d5d5?style=social\u0026logo=twitter)](https://twitter.com/intent/tweet?text=Static%20analysis%20for%20WordPress\u0026url=https%3A%2F%2Fgithub.com%2Fszepeviktor%2Fphpstan-wordpress)\n[![Build Status](https://app.travis-ci.com/szepeviktor/phpstan-wordpress.svg?token=CgYVxsSdNVnRNCDNV3qG\u0026branch=master)](https://app.travis-ci.com/szepeviktor/phpstan-wordpress)\n[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-239922)](https://github.com/phpstan/phpstan)\n\nStatic analysis for the WordPress ecosystem.\n\n- [PHPStan](https://phpstan.org/)\n- [WordPress](https://wordpress.org/)\n\n## Features\n\n- Enables PHPStan to analyze WordPress plugins and themes.\n- Loads the [`php-stubs/wordpress-stubs`](https://github.com/php-stubs/wordpress-stubs) package.\n- Provides dynamic return type extensions for functions that are not covered in\n    [`php-stubs/wordpress-stubs`](https://github.com/php-stubs/wordpress-stubs/blob/master/functionMap.php)\n- Defines some WordPress core constants.\n- Validates optional docblocks before `apply_filters()` and `do_action()` calls,\n    treating the type of the first `@param` as definitive.\n\n## Requirements\n\n- PHPStan 2.0 or higher\n- PHP 7.4 or higher (tested up to PHP 8.3)\n\n## Installation\n\nTo use this extension, require it in [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require --dev szepeviktor/phpstan-wordpress\n```\n\nIf you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!\n\n### Manual Installation\n\nIf you don't want to use `phpstan/extension-installer`, include `extension.neon` in your project's PHPStan config:\n\n```neon\nincludes:\n    - vendor/szepeviktor/phpstan-wordpress/extension.neon\n```\n\n## Configuration\n\nNo additional setup is needed. :smiley:\nJust configure PHPStan - for example - as shown below:\n\n```neon\nparameters:\n    level: 5\n    paths:\n        - plugin.php\n        - inc/\n```\n\nFor more details, visit the [PHPStan Config Reference](https://phpstan.org/config-reference).\n\n:bulb: Use the Composer autoloader or a [custom autoloader](https://github.com/szepeviktor/debian-server-tools/blob/master/webserver/wp-install/wordpress-autoloader.php)!\n\n## Usage\n\nRun the analysis with:\n\n```bash\nvendor/bin/phpstan analyze\n```\n\nthen fix an error and `GOTO 10`!\n\nYou find further information in the `examples` directory,\ne.g. [`examples/phpstan.neon.dist`](/examples/phpstan.neon.dist)\n\n### Usage in WooCommerce Webshops\n\nRefer to [WooCommerce Stubs](https://github.com/php-stubs/woocommerce-stubs) for specific guidance.\n\n### Usage of an `apply_filters()` Docblock\n\nThe WordPress ecosystem often uses PHPDoc docblocks in a non-standard way to\ndocument parameters passed to `apply_filters()`.\nHere’s an example:\n\n```php\n/**\n * Filters the page title when creating an HTML drop-down list of pages.\n *\n * @param string  $title Page title.\n * @param WP_Post $page  Page data object.\n */\n$title = apply_filters( 'list_pages', $title, $page );\n```\n\nThis extension reads these docblocks and instructs PHPStan to treat the filter’s\nreturn type as certain, based on the first `@param` tag. In this example,\nPHPStan interprets `$title` as `string`.\n\nFor best results, ensure the first `@param` tag in these docblocks is accurate.\n\n## Make Your Code Testable\n\n- Write clean OOP code: 1 class per file, and no additional code outside `class Name { ... }`.\n- Use consistent class naming (WPCS or PSR-4) and store classes in a dedicated `inc/` directory.\n- Add precise PHPDoc blocks to classes, properties, methods, functions, and\n    `apply_filters()` calls.\n- Choose your [main plugin file parts](https://github.com/szepeviktor/starter-plugin).\n- Avoid using core constants, use core functions.\n- Avoid bad PHP practices, such as:\n  - functions: `eval`, `extract`, `compact`, `list`\n  - [type juggling](https://www.php.net/manual/en/language.types.type-juggling.php): `$a = '15'; if ($a) ...`\n- If you need robust code try avoiding all kinds of type juggling (e.g. `if` needs a boolean),\n    see [Variable handling functions](https://www.php.net/manual/en/ref.var.php)\n- Avoid enabling `exit_error` in `WP_CLI::launch` or `WP_CLI::runcommand` for improved testability.\n\n## Dirty Corner (FAQ)\n\nWordPress uses conditional function and class definition to allow overrides.\nUse `sed` command to exclude function stubs when they are previously defined.\n\n```bash\nsed -i -e 's#function is_gd_image#function __is_gd_image#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszepeviktor%2Fphpstan-wordpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszepeviktor%2Fphpstan-wordpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszepeviktor%2Fphpstan-wordpress/lists"}