composer-wp-pro-plugins
composer-wp-pro-plugins copied to clipboard
Add EditorConfig and PHPStan
Checklist
- [x] I've read the Contributing page.
- [x] No issue.
- [x] My code is tested.
- [x] My code follows the WordPress code style.
- [x] My code has proper inline documentation.
Description
Follow-up to #59 and fork of #58.
Depends on #58 being merged first.
Added an EditorConfig ruleset to enforce tabs for PHP files and spaces for JSON, Markdown, NEON, YML, and XML files. This should help avoid accidental mixing of tabs if one's IDE supports this feature.
Added a simple Composer script to check for syntax errors in PHP files (uses PHP-CLI's syntax checker):
composer lint
Added PHPStan dependency to help finds bugs and logic flaws. Given that tests are absent and not so simple to write given the proprietary and expensive nature of its target WP plugins.
composer analyze -- --xdebug
PHPStan's situation is a little complicated given this plugin supports multiple versions of different packages (notably Composer and vlucas/phpdotenv). PHPStan can't tell that and reports errors for whichever version is not installed. To resolve this, I've introduced a way to conditionally include different baselines based on what is installed in order to hide "errors" from versions not installed.
This conditional functionality can be greatly reduced if we drop support for older versions of PHP, Composer, and other dependencies.
How has this been tested?
- PHP 8.0
- PHP 7.4
- Composer 1.10
- Composer 2.5
- vlucas/phpdotenv 5.5
- vlucas/phpdotenv 4.3
- vlucas/phpdotenv 3.6
Types of changes
- Fix various issues reported by PHPStan.
- Fixed coding styles according to EditorConfig.
- Added conditionally included baselines for PHP 5–7 and 8+, Composer 1 and 2, Dotenv 3–5.
- Includes subset of changes from #58 (7d3aa9e, 0b1c8af, fb0c1ab).