<commit_before><?php

namespace Modus\Auth;

use Aura\Auth;
use Aura\Auth\Service as AuthService;
use Aura\Auth\Exception;

class Service
{

    protected $error = [];

    public function __construct(
        AuthService\LoginService $loginService,
        AuthService\LogOutService $logoutService,
        AuthService\ResumeService $resumeService,
        Auth\Auth $userObj
    ) {
        $this->loginService = $loginService;
        $this->logoutService = $logoutService;
        $this->resumeService = $resumeService;
        $this->userObj = $userObj;
    }

    public function getUser()
    {
        return $this->userObj;
    }

    public function resume()
    {
        try {
            $this->resumeService->resume($this->userObj);
        } catch (Exception $e) {
            $this->handleException($e);
        }
        return $this->getUser();
    }

    public function authenticate($user = null, $pass = null)
    {
        try {
            $this->loginService->login($this->userObj, ['username' => $user, 'password' => $pass]);
        } catch (Exception $e) {
            $this->handleException($e);
        }
        return $this->getUser();
    }

    public function logOut()
    {
        try {
            $this->logoutService->logout($this->userObj);
        } catch (Exception $e) {
            $this->handleException($e);
        }
        return $this->getUser();
    }

    protected function handleException(Exception $e)
    {
        switch (true) {
            case ($e instanceof Exception\AlgorithmNotAvailable):
                $this->setError('The algorithm specified was unavailable', $e->getMessage());
                break;

            case ($e instanceof Exception\BindFailed):
                $this->setError('LDAP Binding failed.', $e->getMessage());
                break;

            case ($e instanceof Exception\ConnectionFailed):
                $this->setError('The LDAP/IMAP connection failed.', $e->getMessage());
                break;

            case ($e instanceof Exception\FileNotFound):
                $this->setError('The password file could not be found.', $e->getMessage());
                break;

            case ($e instanceof Exception\FileNotReadable):
                $this->setError('The file specified could not be read.', $e->getMessage());
                break;

            case ($e instanceof Exception\MultipleMatches):
                $this->setError('There were multiple matches for your credentials in the database.');
                break;

            case ($e instanceof Exception\PasswordColumnNotSpecified):
                $this->setError('The password column was not specified in the database.');

            case ($e instanceof Exception\PasswordIncorrect):
                $this->setError('The password was incorrect.');
                break;

            case ($e instanceof Exception\PasswordMissing):
                $this->setError('The password was not provided.');
                break;

            case ($e instanceof Exception\UsernameColumnNotSpecified):
                $this->setError('The username column was not specified in the database.');
                break;

            case ($e instanceof Exception\UsernameMissing):
                $this->setError('The username was not provided.');
                break;

            case ($e instanceof Exception\UsernameNotFound):
                $this->setError('The username was not found.');
                break;

            default:<commit_msg>Missing break in a switch statement.<commit_after><?php

namespace Modus\Auth;

use Aura\Auth;
use Aura\Auth\Service as AuthService;
use Aura\Auth\Exception;

class Service
{

    protected $error = [];

    public function __construct(
        AuthService\LoginService $loginService,
        AuthService\LogOutService $logoutService,
        AuthService\ResumeService $resumeService,
        Auth\Auth $userObj
    ) {
        $this->loginService = $loginService;
        $this->logoutService = $logoutService;
        $this->resumeService = $resumeService;
        $this->userObj = $userObj;
    }

    public function getUser()
    {
        return $this->userObj;
    }

    public function resume()
    {
        try {
            $this->resumeService->resume($this->userObj);
        } catch (Exception $e) {
            $this->handleException($e);
        }
        return $this->getUser();
    }

    public function authenticate($user = null, $pass = null)
    {
        try {
            $this->loginService->login($this->userObj, ['username' => $user, 'password' => $pass]);
        } catch (Exception $e) {
            $this->handleException($e);
        }
        return $this->getUser();
    }

    public function logOut()
    {
        try {
            $this->logoutService->logout($this->userObj);
        } catch (Exception $e) {
            $this->handleException($e);
        }
        return $this->getUser();
    }

    protected function handleException(Exception $e)
    {
        switch (true) {
            case ($e instanceof Exception\AlgorithmNotAvailable):
                $this->setError('The algorithm specified was unavailable', $e->getMessage());
                break;

            case ($e instanceof Exception\BindFailed):
                $this->setError('LDAP Binding failed.', $e->getMessage());
                break;

            case ($e instanceof Exception\ConnectionFailed):
                $this->setError('The LDAP/IMAP connection failed.', $e->getMessage());
                break;

            case ($e instanceof Exception\FileNotFound):
                $this->setError('The password file could not be found.', $e->getMessage());
                break;

            case ($e instanceof Exception\FileNotReadable):
                $this->setError('The file specified could not be read.', $e->getMessage());
                break;

            case ($e instanceof Exception\MultipleMatches):
                $this->setError('There were multiple matches for your credentials in the database.');
                break;

            case ($e instanceof Exception\PasswordColumnNotSpecified):
                $this->setError('The password column was not specified in the database.');
                break;

            case ($e instanceof Exception\PasswordIncorrect):
                $this->setError('The password was incorrect.');
                break;

            case ($e instanceof Exception\PasswordMissing):
                $this->setError('The password was not provided.');
                break;

            case ($e instanceof Exception\UsernameColumnNotSpecified):
                $this->setError('The username column was not specified in the database.');
                break;

            case ($e instanceof Exception\UsernameMissing):
                $this->setError('The username was not provided.');
                break;

            case ($e instanceof Exception\UsernameNotFound):
                $this->setError('The username was not found.');
                break;

            default:
{'fraction_non_alphanumeric': 0.11591744416171897, 'fraction_numerical': 0.0, 'mean_word_length': 1.9308202154101077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '878867', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1701, 'n_words': 451}