<commit_before><?php

namespace SilMock\Google\Service\Directory;

use Google_Service_Directory_Tokens;

class Tokens
{
    /** @var string - The path (with file name) to the SQLite database. */
    private $dbFile;
    
    /** @var string - The 'type' field to use in the database. */
    private $dataType = 'directory';
    
    /** @var string - The 'class' field to use in the database */
    private $dataClass = 'tokens';
    
    public function __construct($dbFile = null)
    {
        $this->dbFile = $dbFile;
    }
    
    public function listTokens($userKey, $optParams = array())
    {
        return new Google_Service_Directory_Tokens(array(
            'items' => array(),
        ));
    }
}<commit_msg>Cleanup Tokens and add delete()<commit_after><?php

namespace SilMock\Google\Service\Directory;

use Google_Service_Directory_Token;
use Google_Service_Directory_Tokens;
use Google_Service_Exception;
use SilMock\Google\Service\DbClass;

class Tokens extends DbClass
{
    public function __construct($dbFile = null)
    {
        parent::__construct($dbFile, 'directory', 'tokens');
    }
    
    public function listTokens($userKey, $optParams = []): Google_Service_Directory_Tokens
    {
        return new Google_Service_Directory_Tokens([ 'items' => [] ]);
    }

    /**
     * @throws Google_Service_Exception
     */
    public function delete($userKey, $clientId)
    {
        $this->assertIsValidUserKey($userKey);

        foreach ($this->listTokensFor($userKey) as $recordId => $token) {
            /** @var Google_Service_Directory_Token $token */
            if ($token->clientId === $clientId) {
                $this->removeToken($recordId);
                return;
            }
        }
    }

    protected function assertIsValidUserKey(string $userId)
    {
        if (! $this->isValidEmailAddress($userId)) {
            throw new Google_Service_Exception('Invalid userId: ' . $userId, 400);
        }
    }

    /**
     * Determine whether the given string is a valid email address.
     *
     * @param string $email The email address to check.
     * @return bool Whether the string is a valid email address.
     */
    protected function isValidEmailAddress(string $email): bool
    {
        return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
    }

    protected function listTokensFor(string $userId): array
    {
        return [];
    }

    protected function removeToken($recordId)
    {
        $this->deleteRecordById($recordId);
    }
}
{'fraction_non_alphanumeric': 0.1135005973715651, 'fraction_numerical': 0.0011947431302270011, 'mean_word_length': 2.6511627906976742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7547205', 'n_tokens_mistral': 714, 'n_tokens_neox': 715, 'n_words': 176}