<?php

namespace Application\Service;

class UserService implements \Zend\ServiceManager\ServiceLocatorAwareInterface {

    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
    
    public function getCurrentUserEntity() {
        $uid = $this->getServiceLocator()->get('zfcuser_auth_service')->getIdentity()->getId();
        return $this->getServiceLocator()->get('UserRepository')->find((int) $uid);
    }
}

<?php

namespace Application\Service;

class UserService implements \Zend\ServiceManager\ServiceLocatorAwareInterface {

    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
    
    public function getCurrentUserEntity() {
        if($user = $this->getServiceLocator()->get('zfcuser_auth_service')->getIdentity()) {
            return $this->getServiceLocator()->get('UserRepository')->find((int) $user->getId());
        }
        return null;
    }
}

Fix User Service when guest
Fix User Service when guest