<commit_before><?php
namespace Phlopsi\AccessControl;

use Phlopsi\AccessControl\Exception\LengthException;
use Phlopsi\AccessControl\Exception\RuntimeException;
use Phlopsi\AccessControl\Propel\PermissionQuery as PropelPermissionQuery;
use Phlopsi\AccessControl\Propel\Role as PropelRole;
use Propel\Runtime\Connection\ConnectionInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class Role
{
    /**
     * @var ConnectionInterface|null
     */
    private $connection;

    /**
     * @var PropelRole
     */
    private $role;

    /**
     * @param PropelRole $role
     *
     * @codeCoverageIgnore
     */
    public function __construct(PropelRole $role, ConnectionInterface $connection = null)
    {
        $this->role = $role;
        $this->connection = $connection;
    }

    /**
     * @return string
     *
     * @codeCoverageIgnore
     */
    public function getId()
    {
        return $this->role->getExternalId();
    }

    /**
     * @param string $permission_id
     *
     * @throws LengthException
     * @throws RuntimeException
     */
    public function addPermission($permission_id)
    {
        if (empty($permission_id)) {
            throw new LengthException(LengthException::ARGUMENT_IS_EMPTY_STRING);
        }

        try {
            $permission = PropelPermissionQuery::create()
                ->findOneByExternalId($permission_id, $this->connection);
        } catch (\Exception $exception) {
            throw new RuntimeException('', 0, $exception);
        }

        if (is_null($permission)) {
            throw new RuntimeException(sprintf(RuntimeException::ENTITY_NOT_FOUND, $permission_id));
        }

        $this->role
            ->addPermission($permission)
            ->save($this->connection);
    }

    /**
     * @param string $permission_id
     *
     * @throws LengthException
     * @throws RuntimeException
     */
    public function removePermission($permission_id)
    {
        if (empty($permission_id)) {
            throw new LengthException(LengthException::ARGUMENT_IS_EMPTY_STRING);
        }

        try {
            $permission = PropelPermissionQuery::create()
                ->findOneByExternalId($permission_id, $this->connection);
        } catch (\Exception $exception) {
            throw new RuntimeException('', 0, $exception);
        }

        if (is_null($permission)) {
            throw new RuntimeException(sprintf(RuntimeException::ENTITY_NOT_FOUND, $permission_id));
        }

        $this->role
            ->removePermission($permission)
            ->save($this->connection);
    }
}
<commit_msg>Add missing try-catch blocks to Role<commit_after><?php
namespace Phlopsi\AccessControl;

use Phlopsi\AccessControl\Exception\LengthException;
use Phlopsi\AccessControl\Exception\RuntimeException;
use Phlopsi\AccessControl\Propel\PermissionQuery as PropelPermissionQuery;
use Phlopsi\AccessControl\Propel\Role as PropelRole;
use Propel\Runtime\Connection\ConnectionInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class Role
{
    /**
     * @var ConnectionInterface|null
     */
    private $connection;

    /**
     * @var PropelRole
     */
    private $role;

    /**
     * @param PropelRole $role
     *
     * @codeCoverageIgnore
     */
    public function __construct(PropelRole $role, ConnectionInterface $connection = null)
    {
        $this->role = $role;
        $this->connection = $connection;
    }

    /**
     * @return string
     *
     * @codeCoverageIgnore
     */
    public function getId()
    {
        return $this->role->getExternalId();
    }

    /**
     * @param string $permission_id
     *
     * @throws LengthException
     * @throws RuntimeException
     */
    public function addPermission($permission_id)
    {
        if (empty($permission_id)) {
            throw new LengthException(LengthException::ARGUMENT_IS_EMPTY_STRING);
        }

        try {
            $permission = PropelPermissionQuery::create()
                ->findOneByExternalId($permission_id, $this->connection);
        } catch (\Exception $exception) {
            throw new RuntimeException('', 0, $exception);
        }

        if (is_null($permission)) {
            throw new RuntimeException(sprintf(RuntimeException::ENTITY_NOT_FOUND, $permission_id));
        }

        try {
            $this->role
                ->addPermission($permission)
                ->save($this->connection);
        } catch (\Exception $exception) {
            throw new RuntimeException('', 0, $exception);
        }
    }

    /**
     * @param string $permission_id
     *
     * @throws LengthException
     * @throws RuntimeException
     */
    public function removePermission($permission_id)
    {
        if (empty($permission_id)) {
            throw new LengthException(LengthException::ARGUMENT_IS_EMPTY_STRING);
        }

        try {
            $permission = PropelPermissionQuery::create()
                ->findOneByExternalId($permission_id, $this->connection);
        } catch (\Exception $exception) {
            throw new RuntimeException('', 0, $exception);
        }

        if (is_null($permission)) {
            throw new RuntimeException(sprintf(RuntimeException::ENTITY_NOT_FOUND, $permission_id));
        }

        try {
            $this->role
                ->removePermission($permission)
                ->save($this->connection);
        } catch (\Exception $exception) {
            throw new RuntimeException('', 0, $exception);
        }
    }
}

{'fraction_non_alphanumeric': 0.11579712779494637, 'fraction_numerical': 0.0010907107798582077, 'mean_word_length': 2.2926391382405744, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '1192794', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1467, 'n_words': 277}