đ Dependency Assertions â
toOnlyDependOn() â
You can use regexes to select dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOn(
names: [ArrayAccess::class, /* ... */],
patterns: ['App\Dto.+', /* ... */],
)
);toOnlyDependOnAttribute() â
If you use the rule toHaveAttribute(), they are included by default in the permitted dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOnAttribute(
names: [\Attribute::class, /* ... */],
patterns: ['Attributes\Custom.+', /* ... */],
)
);toOnlyDependOnImplementation() â
If you use the rules toImplement() and toOnlyImplement(), they are included by default in the permitted dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOnImplementation(
names: [\ArrayAccess::class, /* ... */],
patterns: ['Contracts\Dto.+', /* ... */],
)
);toOnlyDependOnInheritance() â
If you use the rule toExtend(), they are included by default in the permitted dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOnInheritance(
names: [Controller::class, /* ... */],
patterns: ['Controllers\Admin.+', /* ... */],
)
);toOnlyDependOnUseTrait() â
If you use the rules toUseTrait() and toOnlyUseTrait(), they are included by default in the permitted dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOnUseTrait(
names: [\HasFactor::class, /* ... */],
patterns: ['Concerns\Models.+', /* ... */],
)
);toNotDependOn() â
You can use regexes to select dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toNotDependOn(
names: [ArrayAccess::class, /* ... */],
patterns: ['App\Dto.+', /* ... */],
)
);toOnlyDependOnFunction() â
You can use regexes to select dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOnFunction(
names: ['strtolower', /* ... */],
patterns: ['array_.+', /* ... */],
)
);toNotDependOnFunction() â
Prohibit the use of specific functions. You can use regexes to select dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toNotDependOnFunction(
names: ['goto', /* ... */],
patterns: ['.+exec', /* ... */],
)
);toOnlyDependOnPhpDoc() â
Verifies that all class references appearing in phpDoc annotations (@param, @return, @var, @throws, etc.) belong only to the authorised namespaces.
You can use regexes to select dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toOnlyDependOnPhpDoc(
names: [\ArrayAccess::class, /* ... */],
patterns: ['App\Dto.+', /* ... */],
)
);Violation message:
Resource <class> must only depend on these phpDoc namespaces <authorised> but depends on <forbidden>toNotDependOnPhpDoc() â
Prohibit the use of specific class references inside phpDoc annotations.
You can use regexes to select dependencies.
$this
->allClasses()
->should(fn(Expr $expr) => $expr
->toNotDependOnPhpDoc(
names: [LegacyClass::class, /* ... */],
patterns: ['Legacy\\.+', /* ... */],
)
);Violation message:
Resource <class> must not depend on these phpDoc namespaces <forbidden> but depends on <found>