The reason there isn’t normally a need to do so is that you normally don’t have functions in enums that require knowledge of external objects – there’s rarely a need to do that.
I would argue that it’s also not really necessary here, either. It looks to me as if you’re using the order and user objects to determine the user’s role in relation to the order (buyer, seller or admin) – but the logic of determining that doesn’t belong inside the order status enum. That’s a property of either the order (or perhaps the current user), not the order status. The order status should just receive information about it, rather than containing logic to calculate it.
I would do something like this:
// OrderUserRole enum to determine user’s role
enum OrderUserRole {
case Buyer;
case Seller;
case Admin;
}
// Order class
public function userRole() {
if ($this->user->id == $this->buyer_id) return OrderUserRole::Buyer;
if ($this->user->id == $this->seller_id) return OrderUserRole::Seller;
return OrderUserRole::Admin;
}
public getStatusBadgeType() {
return $this->status_id->badgeType($this->userRole());
}
// OrderStatus enum
public function badgeType(OrderUserRole $role) {
switch ($role) {
case OrderUserRole::Buyer:
return match ($this) {
self::AwaitingPayment => 'some-badge',
self::PaymentReceived => 'another-badge'
}
break;
case OrderUserRole::Seller:
…
break;
case OrderUserRole::Admin:
…
break;
}
}