I have Cyclomatic Complexity issue with a switch case statement, so I need to refactor switch/case block of code.
I trying to create an array with keys and as value to set method call i.e $this->authChecker->isGranted(User::ROLE_ADMIN)
$attributeResolver = [
self::OPEN_FORM => '$this->authChecker->isGranted(User::ROLE_USER)',
self::CREATE => '$this->authChecker->isGranted(User::ROLE_ADMIN)',
self::EDIT => '...',
self::DISABLE => '...',
];
And for a call to use something like this,
return $attributeResolver[$attribute];
I want to store method call in the string to avoid unnecessary service calls.
Is this is posible?