𧲠Relation Assertions â
toExtend() â
php
$this
->allClasses()
->fromRaw('<?php class Foo extends \Exception {}')
->should(fn(Expr $expr) => $expr->toExtend(Exception::class));toNotExtend() â
Opposite of toExtend(). Fails if the resource extends one of the given classes; one violation is reported per forbidden parent. To forbid any parent, use toExtendNothing().
php
$this
->allClasses()
->fromDir('src/Domain')
->should(fn(Expr $expr) => $expr->toNotExtend(Model::class));Violation message
Resource Foo must not extend ModeltoExtendNothing() â
php
$this
->allClasses()
->fromRaw('<?php class Foo {}')
->should(fn(Expr $expr) => $expr->toExtendNothing());toImplement() â
php
$this
->allClasses()
->fromRaw('<?php class Foo implements \ArrayAccess, \JsonSerializable {}')
->should(fn(Expr $expr) => $expr->toImplement(ArrayAccess::class));toNotImplement() â
Opposite of toImplement(). Fails if the resource implements one of the given interfaces; one violation is reported per forbidden interface. To forbid any interface, use toImplementNothing().
php
$this
->allClasses()
->fromDir('src/Domain')
->should(fn(Expr $expr) => $expr->toNotImplement(Serializable::class));Violation message
Resource Foo must not implement SerializabletoImplementNothing() â
php
$this
->allClasses()
->fromRaw('<?php class Foo {}')
->should(fn(Expr $expr) => $expr->toImplementNothing());toOnlyImplement() â
php
$this
->allClasses()
->fromRaw('<?php class Foo implements \ArrayAccess {}')
->should(fn(Expr $expr) => $expr->toOnlyImplement(ArrayAccess::class));toUseTrait() â
php
$this
->allClasses()
->fromRaw('<?php class Foo { use Bar, Baz; }')
->should(fn(Expr $expr) => $expr->toUseTrait(Bar::class));toNotUseTrait() â
php
$this
->allClasses()
->fromRaw('<?php class Foo {}')
->should(fn(Expr $expr) => $expr->toNotUseTrait());toOnlyUseTrait() â
php
$this
->allClasses()
->fromRaw('<?php class Foo { use Bar; }')
->should(fn(Expr $expr) => $expr->toOnlyUseTrait(Bar::class));toHaveAttribute() â
php
$this
->allClasses()
->fromRaw('<?php #[\Deprecated] class Foo {}')
->should(fn(Expr $expr) => $expr->toHaveAttribute(Deprecated::class));toHaveNoAttribute() â
php
$this
->allClasses()
->fromRaw('<?php class Foo {}')
->should(fn(Expr $expr) => $expr->toHaveNoAttribute());toNotHaveAttribute() â
Opposite of toHaveAttribute(). Fails if the resource carries the given attribute; one violation is reported per occurrence. To forbid any attribute, use toHaveNoAttribute().
php
$this
->allClasses()
->fromDir('src')
->should(fn(Expr $expr) => $expr->toNotHaveAttribute(Deprecated::class));toHaveOnlyAttribute() â
php
$this
->allClasses()
->fromRaw('<?php #[\Deprecated] class Foo {}')
->should(fn(Expr $expr) => $expr->toHaveOnlyAttribute(Deprecated::class));