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
42 changes: 40 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Each rule follows a 3-component structure:
### Key Files
- `config/extension.neon` - Central dependency injection & parameter schema definition
- `tests/Rules/*/config/*.neon` - Per-test configuration files that override defaults
- `tests/Rules/*/Fixture/ExampleClass.php` - Test fixtures with various naming patterns
- Though this is the primary fixture we have used so far, feel free to add more or different fixture files if needed for specific test cases.
- `tests/Rules/*/Fixture/*.php` - Test fixtures with various naming patterns (one class/trait/interface/enum per file)

## Critical Development Workflows

Expand Down Expand Up @@ -148,6 +147,45 @@ $pattern .= '$/';

## Test Conventions

### PSR-4 Fixture File Standards
**CRITICAL**: All test fixture files MUST follow PSR-4 autoloading standards:

1. **One class/trait/interface/enum per file**: Each PHP type must be in its own file
2. **Filename matches type name**: A class `MyClass` must be in `MyClass.php`
3. **No multi-type files**: Never put multiple classes, traits, interfaces, or enums in the same file

**Example - CORRECT:**
```
tests/Rules/MyRule/Fixture/
├── ExampleClass.php # Contains only: class ExampleClass
├── AnotherClass.php # Contains only: class AnotherClass
├── ExampleTrait.php # Contains only: trait ExampleTrait
├── ExampleInterface.php # Contains only: interface ExampleInterface
└── ExampleEnum.php # Contains only: enum ExampleEnum
```

**Example - INCORRECT:**
```php
// ExampleClass.php - DON'T DO THIS
class ExampleClass {}
class AnotherClass {} // Should be in AnotherClass.php
trait ExampleTrait {} // Should be in ExampleTrait.php
```

When tests need multiple fixture types, list them all in the `$this->analyse()` call:
```php
$this->analyse(
[
__DIR__ . '/Fixture/ExampleClass.php',
__DIR__ . '/Fixture/AnotherClass.php',
__DIR__ . '/Fixture/ExampleTrait.php',
],
[
// expected errors with line numbers
]
);
```

### Test Structure
Each rule has multiple test classes covering all possible different configuration combinations, examples are:
- `DefaultOptionsTest` - Default configuration
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
- [📚 Available Rules](#-available-rules)
- [🔧 Configuration](#-configuration)
- [🎯 Inspiration](#-inspiration)
- [🤝 Contributing](#-contributing)
- [📄 License](#-license)
- [🙏 Acknowledgments](#-acknowledgments)

Expand Down Expand Up @@ -116,6 +115,7 @@ parameters:
| **[ForbidEvalExpressions](docs/ForbidEvalExpressions.md)** | Detects and reports usage of eval expressions | Eval Expressions |
| **[ForbidExitExpressions](docs/ForbidExitExpressions.md)** | Detects and reports usage of exit and die expressions | Exit Expressions |
| **[ForbidGotoStatements](docs/ForbidGotoStatements.md)** | Detects and reports usage of goto statements | Goto Statements |
| **[CyclomaticComplexity](docs/CyclomaticComplexity.md)** | Detects methods with high cyclomatic complexity | Methods, Classes |
| **[NumberOfChildren](docs/NumberOfChildren.md)** | Detects classes with too many direct child classes | Class Hierarchy |
| **[TooManyMethods](docs/TooManyMethods.md)** | Detects classes with too many methods | Classes, Interfaces, Traits, Enums |

Expand Down Expand Up @@ -163,9 +163,10 @@ Originally inspired by [**PHPMD - PHP Mess Detector**](https://phpmd.org/), this

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

## 🤝 Contributing
[//]: # (## 🤝 Contributing)

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
[//]: # ()
[//]: # (We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.)

### Development Setup

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"paratest --configuration phpunit.xml"
],
"cs-fix": [
"export PHP_CS_FIXER_IGNORE_ENV=1 ; ./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix -v --config=./php-cs-fixer.php"
"./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix -v --config=./php-cs-fixer.php"
],
"format": [
"@cs-fix"
Expand Down
Loading