DEV Community


Discussion on: Writing Clean Code

ryanwinchester profile image
Ryan Winchester • Edited

Nice job, I've been liking these kind of posts you've been doing lately, and your final function is way better.

However, I feel like playing along, too. How about this? :)


  function canView(string $scope, int $owner_id): bool
      return $scope === 'public' || $this->userCanView(Auth::user(), $owner_id);

  function userCanView(User $user, int $owner_id): bool
      return $user->hasRole('admin') || $user->id === $owner_id;

I don't know the context, but I'm pretty sure it doesn't even matter if the $scope is 'private', if the current user is the owner.