src/Model/Table/TokensTable.php
public function deleteExpired(Token $entity = null)
    {
        $conditions[] = ['expiry <' => new Time];

        if (!empty($entity->token)) {
            $conditions[] = ['token' => $entity->token];
        }

        if (!empty($entity->user_id)) {
            $conditions[] = ['user_id' => $entity->user_id];
        }

        return $this->deleteAll(['OR' => $conditions]);
    }
public function deleteExpired(Token $entity = null)
    {
        $conditions[] = ['expiry <' => new Time];

        if (!empty($entity->token)) {
            $conditions[] = ['token' => $entity->token];
        }

        if (!empty($entity->user_id)) {
            $conditions[] = ['user_id' => $entity->user_id];
        }

        return $this->deleteAll(['OR' => $conditions]);
    }
public function deleteExpired ( Token $ entity = null ) { $ conditions [ ] = [ 'expiry <' => new Time ] ; if ( ! empty ( $ entity -> token ) ) { $ conditions [ ] = [ 'token' => $ entity -> token ] ; } if ( ! empty ( $ entity -> user_id ) ) { $ conditions [ ] = [ 'user_id' => $ entity -> user_id ] ; } return $ this -> deleteAll ( [ 'OR' => $ conditions ] ) ; }
Deletes all expired tokens.

If a `$token` entity is passed, it also clears tokens with the same
token value and/or the same user.

This method should be called before creating a new token. In fact, it
prevents a user from having more than token or a token is created with
the same token value.
@param \Tokens\Model\Entity\Token|null $entity Token entity
@return int Affected rows
Deletes all expired tokens .