diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..a29adcc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,109 @@ +# Contributing to MeliorStan + +Thank you for your interest in contributing to MeliorStan! This document provides guidelines and instructions for contributing to the project. + +## 📋 Table of Contents + +- [Development Setup](#development-setup) +- [Project Architecture](#project-architecture) +- [Adding New Rules](#adding-new-rules) +- [Testing](#testing) + +## Development Setup + +### Prerequisites + +- PHP 8.3 or higher +- Composer + +### Installation + +```bash +git clone https://github.com/Orrison/MeliorStan.git +cd MeliorStan +composer install +``` + +### Available Commands + +| Command | Description | +|---------|-------------| +| `composer test` | Run all tests with paratest | +| `composer format` | Auto-fix code style with PHP-CS-Fixer | +| `composer analyze` | Run PHPStan analysis | + +## Project Architecture + +Each rule typically follows a consistent component structure as follows: + +``` +src/Rules/{RuleName}/ +├── {RuleName}Rule.php # Main rule implementing Rule +├── Config.php # Configuration class (if rule has options) + +tests/Rules/{RuleName}/ +├── config/ +│ ├── default.neon # Default configuration test +│ └── {option}.neon # Per-option configuration tests +├── Fixture/ +│ └── ExampleClass.php # Test fixtures +├── DefaultTest.php # Default configuration test +└── {Option}Test.php # Per-option tests +``` + +### Key Files + +| File | Purpose | +|------|---------| +| `config/extension.neon` | Central dependency injection & parameter schema definition | +| `tests/Rules/*/config/*.neon` | Per-test configuration files that override defaults | +| `tests/Rules/*/Fixture/*.php` | Test fixtures with various code patterns | + +## Adding New Rules + +1. Follow the established architecture pattern +2. Include comprehensive tests +3. Update documentation +4. Ensure all checks pass: `composer format && composer analyze && composer test` + +## Testing + +### Running Tests + +```bash +# Run all tests +composer test + +# Run specific rule tests +./vendor/bin/phpunit tests/Rules/{RuleName}/ + +# Run a single test file +./vendor/bin/phpunit tests/Rules/{RuleName}/DefaultTest.php +``` + +### Test Conventions + +- Each rule has multiple test classes covering all configuration combinations +- Tests use exact line numbers from fixture files +- **Always use error message constants** in test assertions, never hardcoded strings + +```php +// ✓ Correct - using constants +$this->analyse([__DIR__ . '/Fixture/Example.php'], [ + [MyRule::ERROR_MESSAGE, 14], + [sprintf(MyRule::ERROR_MESSAGE_TEMPLATE, 'value', 3), 20], +]); + +// ✗ Wrong - hardcoded strings +$this->analyse([__DIR__ . '/Fixture/Example.php'], [ + ['Some hardcoded error message.', 14], +]); +``` + +## Questions? + +If you have questions or need help, please [open an issue](https://github.com/orrison/meliorstan/issues). + +--- + +Thank you for contributing to MeliorStan! 🎉 diff --git a/README.md b/README.md index 5add5c0..d68240f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-# MeliorStan 🛡️ +# MeliorStan **Advanced PHPStan Rules for Superior Code Quality** @@ -161,28 +161,11 @@ parameters: Originally inspired by [**PHPMD - PHP Mess Detector**](https://phpmd.org/), this project provides modern PHPStan equivalents with enhanced configurability and PHP 8+ features. -> **Note**: While inspired by PHPMD, these rules are not exact replicas. They offer additional customization options and are adapted for PHPStan's architecture and modern PHP practices. +> **Note**: While inspired by PHPMD, these rules are not exact replicas. They may offer additional or renamed customization options and are adapted for PHPStan's architecture and modern PHP practices. -[//]: # (## 🤝 Contributing) +## 🤝 Contributing -[//]: # () -[//]: # (We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.) - -### Development Setup - -```bash -git clone https://github.com/Orrison/MeliorStan.git -cd MeliorStan -composer install -composer test -``` - -### Adding New Rules - -1. Follow the established architecture pattern -2. Include comprehensive tests -3. Update documentation -4. Ensure all checks pass: `composer format && composer analyze && composer test` +We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details. ## 📄 License @@ -192,8 +175,6 @@ This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) - [**PHPStan**](https://phpstan.org/) - The foundation of modern PHP static analysis - [**PHPMD**](https://phpmd.org/) - Original inspiration for code quality rules -- [**PHP-Parser**](https://github.com/nikic/PHP-Parser) - AST parsing capabilities -- **PHP Community** - For continuous improvement of PHP tooling --- @@ -201,6 +182,6 @@ This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) **Made with ❤️ for the PHP community** -[📖 Documentation](docs/) • [🐛 Report Issues](https://github.com/orrison/meliorstan/issues) • [💡 Request Features](https://github.com/orrison/meliorstan/discussions) +[📖 Documentation](docs/) • [🐛 Report Issues](https://github.com/orrison/meliorstan/issues)