<commit_before><?php
/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 *
 * @copyright Copyright (c) 2016, Project Seminar "PSSL16" at the University of Muenster.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

namespace OCA\OAuth2\Db;

use InvalidArgumentException;
use \OCP\AppFramework\Db\Entity;
use \OCP\IDb;
use \OCP\AppFramework\Db\Mapper;

class AuthorizationCodeMapper extends Mapper {

    public function __construct(IDb $db) {
        parent::__construct($db, 'oauth2_authorization_codes');
    }

    /**
     * Selects an authorization code by its ID.
     *
     * @param string $id The authorization code's ID.
     *
     * @return Entity The authorization code entity.
     *
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found.
     * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more
     * than one result.
     */
    public function find($id) {
		if (is_null($id)) {
			throw new InvalidArgumentException('id must not be null');
		}

        $sql = 'SELECT * FROM `'. $this->tableName . '` WHERE `id` = ?';
        return $this->findEntity($sql, array($id), null, null);
    }

    /**
     * Selects an authorization code by its code.
     *
     * @param string $code The authorization code.
     *
     * @return Entity The authorization code entity.
     *
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found.
     * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more
     * than one result.
     */
    public function findByCode($code) {
        $sql = 'SELECT * FROM `'. $this->tableName . '` WHERE `code` = ?';
        return $this->findEntity($sql, array($code), null, null);
    }

	public function findMany(array $ids) {
		// TODO: implement filtering with many IDS
		$sql = 'SELECT * FROM `'. $this->tableName . '` WHERE `id` IN ?';
		return $this->findEntities($sql, array($ids), null, null);
	}

    /**
     * Selects all authorization codes.
     *
     * @param int $limit The maximum number of rows.
     * @param int $offset From which row we want to start.
	 *
     * @return array All authorization codes.
     */
    public function findAll($limit = null, $offset = null) {
        $sql = 'SELECT * FROM `' . $this->tableName . '`';
        return $this->findEntities($sql, [], $limit, $offset);
    }

	/**
	 * Deletes all authorization codes for given client and user ID.
	 *
	 * @param string $clientId The client ID.
	 * @param string $userId The user ID.
	 */
	public function deleteByClientUser($clientId, $userId) {
		if (is_null($clientId) || is_null($userId)) {
			throw new InvalidArgumentException('client_id and user_id must not be null');
		}
<commit_msg>Refactor AuthorizationCodeMapper<commit_after><?php
/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 *
 * @copyright Copyright (c) 2016, Project Seminar "PSSL16" at the University of Muenster.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

namespace OCA\OAuth2\Db;

use InvalidArgumentException;
use \OCP\AppFramework\Db\Entity;
use \OCP\IDb;
use \OCP\AppFramework\Db\Mapper;

class AuthorizationCodeMapper extends Mapper {

    public function __construct(IDb $db) {
        parent::__construct($db, 'oauth2_authorization_codes');
    }

    /**
     * Selects an authorization code by its ID.
     *
     * @param string $id The authorization code's ID.
     *
     * @return Entity The authorization code entity.
     *
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found.
     * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more
     * than one result.
     */
    public function find($id) {
		if (is_null($id)) {
			throw new InvalidArgumentException('id must not be null');
		}

        $sql = 'SELECT * FROM `'. $this->tableName . '` WHERE `id` = ?';
        return $this->findEntity($sql, array($id), null, null);
    }

    /**
     * Selects an authorization code by its code.
     *
     * @param string $code The authorization code.
     *
     * @return Entity The authorization code entity.
     *
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found.
     * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more
     * than one result.
     */
    public function findByCode($code) {
        $sql = 'SELECT * FROM `'. $this->tableName . '` WHERE `code` = ?';
        return $this->findEntity($sql, array($code), null, null);
    }

    /**
     * Selects all authorization codes.
     *
     * @param int $limit The maximum number of rows.
     * @param int $offset From which row we want to start.
	 *
     * @return array All authorization codes.
     */
    public function findAll($limit = null, $offset = null) {
        $sql = 'SELECT * FROM `' . $this->tableName . '`';
        return $this->findEntities($sql, [], $limit, $offset);
    }

	/**
	 * Deletes all authorization codes for given client and user ID.
	 *
	 * @param string $clientId The client ID.
	 * @param string $userId The user ID.
	 */
	public function deleteByClientUser($clientId, $userId) {
		if (is_null($clientId) || is_null($userId)) {
			throw new InvalidArgumentException('client_id and user_id must not be null');
		}

{'fraction_non_alphanumeric': 0.11665375677769171, 'fraction_numerical': 0.003718048024786987, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '800993', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1883, 'n_words': 657}