Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ services:
- phpstan.rules.rule

# Dependency constraints - enforce layer boundaries
# Note: Use ForbiddenDependenciesRule (DependencyConstraintsRule is deprecated)
-
class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
class: Phauthentic\PHPStanRules\Architecture\ForbiddenDependenciesRule
arguments:
forbiddenDependencies:
# Domain layer cannot depend on Application, Infrastructure, or Presentation
Expand Down
29 changes: 25 additions & 4 deletions docs/rules/Dependency-Constraints-Rule.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Dependency Constraints Rule

> **⚠️ DEPRECATED:** This rule has been renamed to `ForbiddenDependenciesRule`. The `DependencyConstraintsRule` class is kept for backward compatibility but will be removed in a future major version. Please update your configuration to use `ForbiddenDependenciesRule` instead.

Enforces dependency constraints between namespaces by checking `use` statements and optionally fully qualified class names (FQCNs).

The constructor takes an array of namespace dependencies. The key is the namespace that should not depend on the namespaces in the array of values.
Expand All @@ -10,6 +12,21 @@ In the example below nothing from `App\Domain` can depend on anything from `App\

### Basic Usage (Use Statements Only)

**Recommended (using new class name):**

```neon
-
class: Phauthentic\PHPStanRules\Architecture\ForbiddenDependenciesRule
arguments:
forbiddenDependencies: [
'/^App\\Domain(?:\\\w+)*$/': ['/^App\\Controller\\/']
]
tags:
- phpstan.rules.rule
```

**Deprecated (backward compatibility):**

```neon
-
class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
Expand All @@ -23,9 +40,11 @@ In the example below nothing from `App\Domain` can depend on anything from `App\

### With FQCN Checking Enabled

**Recommended (using new class name):**

```neon
-
class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
class: Phauthentic\PHPStanRules\Architecture\ForbiddenDependenciesRule
arguments:
forbiddenDependencies: [
'/^App\\Capability(?:\\\w+)*$/': [
Expand All @@ -40,9 +59,11 @@ In the example below nothing from `App\Domain` can depend on anything from `App\

### With Selective Reference Types

**Recommended (using new class name):**

```neon
-
class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
class: Phauthentic\PHPStanRules\Architecture\ForbiddenDependenciesRule
arguments:
forbiddenDependencies: [
'/^App\\Capability(?:\\\w+)*$/': [
Expand Down Expand Up @@ -86,7 +107,7 @@ This example prevents usage of PHP's built-in `DateTime` and `DateTimeImmutable`

```neon
-
class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
class: Phauthentic\PHPStanRules\Architecture\ForbiddenDependenciesRule
arguments:
forbiddenDependencies: [
'/^App\\Capability(?:\\\w+)*$/': [
Expand All @@ -113,7 +134,7 @@ If you only want to check specific reference types (e.g., to improve performance

```neon
-
class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
class: Phauthentic\PHPStanRules\Architecture\ForbiddenDependenciesRule
arguments:
forbiddenDependencies: [
'/^App\\Capability(?:\\\w+)*$/': [
Expand Down
Loading