Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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<NodeType>
├── 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! 🎉
29 changes: 5 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

# MeliorStan 🛡️
# MeliorStan

**Advanced PHPStan Rules for Superior Code Quality**

Expand Down Expand Up @@ -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]&#40;CONTRIBUTING.md&#41; 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

Expand All @@ -192,15 +175,13 @@ 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

---

<div align="center">

**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)

</div>