{"id":25940699,"url":"https://github.com/luc45/stubz","last_synced_at":"2026-02-17T20:35:44.459Z","repository":{"id":278684864,"uuid":"936370952","full_name":"Luc45/stubz","owner":"Luc45","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-17T16:25:12.000Z","size":16699,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-18T18:56:49.837Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Luc45.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-02-21T01:03:51.000Z","updated_at":"2025-10-17T16:22:00.000Z","dependencies_parsed_at":"2025-07-27T01:28:49.827Z","dependency_job_id":null,"html_url":"https://github.com/Luc45/stubz","commit_stats":null,"previous_names":["luc45/stubz"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Luc45/stubz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luc45%2Fstubz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luc45%2Fstubz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luc45%2Fstubz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luc45%2Fstubz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Luc45","download_url":"https://codeload.github.com/Luc45/stubz/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luc45%2Fstubz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29557414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T20:14:27.083Z","status":"ssl_error","status_checked_at":"2026-02-17T20:14:26.018Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-03-04T05:18:32.553Z","updated_at":"2026-02-17T20:35:39.444Z","avatar_url":"https://github.com/Luc45.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PHPStan - Level 10](https://github.com/Luc45/stubz/actions/workflows/phpstan.yml/badge.svg)](https://github.com/Luc45/stubz/actions/workflows/phpstan.yml)\n[![PHPUnit](https://github.com/Luc45/stubz/actions/workflows/phpunit.yml/badge.svg)](https://github.com/Luc45/stubz/actions/workflows/phpunit.yml)\n\n# Stubz for WordPress Plugins\n\n**Stubz** is a command-line utility designed to generate **PHP stub files** specifically tailored for WordPress plugins,\nalthough it supports any PHP codebase. PHP stubs simplify static analysis by providing a lightweight representation of\nyour plugin's classes, traits, interfaces, functions, and constants, excluding implementation logic.\n\nStubz was initially developed to support the **Quality Insights Toolkit (QIT)** at **Automattic**, helping to enhance\nthe reliability and accuracy of static code analysis within WordPress plugin ecosystems.\n\nWordPress operates as an **event-driven framework**, meaning many plugins define classes and functions within event\ncallbacks (hooks). A common pattern in WordPress plugins that trips static code analysis involves defining classes\ninside action callbacks. For example:\n\n```php\nadd_action('plugins_loaded', function() {\n    class MyPluginMainClass {\n        // class logic\n    }\n});\n```\n\nIn static analysis tools like PHPStan, there's no guarantee the `plugins_loaded` action will ever be invoked. As a\nresult, the tool fails to recognize dynamically defined classes, producing false positives or \"class not found\" errors.\n\nStubz resolves this issue by **\"flattening\" the code definitions**. It moves class, function, and constant definitions\nout of callbacks, making them readily discoverable for static analysis.\n\n## Recommended Usage\n\n### Using QIT (WooCommerce Marketplace Extensions)\n\nFor WooCommerce extensions distributed via the WooCommerce.com Marketplace, the recommended approach is to use the\n[PHPStan Managed Tests provided by QIT](https://qit.woo.com/docs/managed-tests/phpstan). QIT's managed PHPStan tests automatically\nleverage Stubz, greatly simplifying your workflow.\n\n### Using PHPStan Directly (General Plugins)\n\nIf you're working with general WordPress plugins, you can manually configure PHPStan to work with Stubz as follows:\n\nPHPStan differentiates between two important concepts:\n\n- **Scan:** PHPStan scans files to discover classes, functions, constants, and other code structures.\n- **Analyse:** PHPStan analyses the scanned files for potential errors, type mismatches, incorrect method calls, and\n  other code quality issues.\n\nConfigure PHPStan manually by:\n\n- **Analysing** your plugin's actual source code for code quality:\n\n```bash\n./vendor/bin/phpstan analyse ./src\n```\n\n- **Scanning** the generated stubs to ensure dynamically defined entities are recognized:\n\n```neon\nparameters:\n    scanDirectories:\n        - ./src-stubs\n```\n\nThis configuration ensures accurate static analysis while eliminating common WordPress-specific false positives.\n\n## Features\n\n- **Generates stubs** for classes, interfaces, traits, enums, functions, and constants.\n- Supports complex, nested WordPress-specific patterns.\n- Handles modern PHP features including:\n    - Final \u0026 abstract classes and methods\n    - Readonly properties (PHP 8.1+)\n    - Enums (PHP 8.1+), including `case`s\n    - Attributes (PHP 8+), with reflection on arguments\n    - Intersection \u0026 union types, typed properties, constructor promotion\n- **Exclude** specific directories/files using `--exclude \u003cdir\u003e`.\n- **Custom Finder mode** (`--finder \u003cfile.php\u003e`) for advanced queries.\n\n## Requirements\n\n- **PHP 8.2** or later\n- Composer dependencies (`roave/better-reflection`, `symfony/finder`)\n\n## Quick Start Guide\n\n1. Install Stubz using Composer:\n\n   ```bash\n   composer require lucasbustamante/stubz --dev\n   ```\n\n2. Generate stubs for your plugin:\n\n   ```bash\n   ./vendor/bin/stubz ./src ./src-stubs\n   ```\n\n### Excluding Directories\n\nExclude directories like vendor, tests, or build artifacts:\n\n```bash\n./vendor/bin/stubz --exclude vendor --exclude tests ./src ./src-stubs\n```\n\n### Using a Custom Finder\n\nFor more complex inclusion/exclusion logic, create a `finder.php`:\n\n```php\nuse Symfony\\Component\\Finder\\Finder;\n\n$finder = Finder::create()\n    -\u003efiles()\n    -\u003ein(__DIR__ . '/src')\n    -\u003ename('*.php')\n    -\u003eexclude('tests');\n\nreturn $finder;\n```\n\nThen run Stubz:\n\n```bash\n./vendor/bin/stubz --finder finder.php ./src-stubs\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluc45%2Fstubz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluc45%2Fstubz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluc45%2Fstubz/lists"}