<commit_before><?php

Class UserModel extends Model{

    public function __construct($database){ 
        parent::__construct($database);
    }

    function __destruct() {
        parent::__destruct();
    }

    public function createUser($email, $password, $displayName){
        try {
            $data = array('email'=>$email, 'password'=>$password, 'displayName'=>$displayName);
            $sql = 'INSERT INTO users (email, password, displayName) value (:email, :password, :displayName)';
            $statement = $this->connection->prepare($sql);
            $statement->execute($data);
        }
        catch(PDOException $e) {
            echo $e;
        }
        return $this->connection->lastInsertId();
    }

    public function createUserTwitter($twitter_id, $displayName){
        try {
            $data = array('twitter'=>$twitter_id, 'displayName'=>$displayName);
            $sql = 'INSERT INTO users (twitter, displayName) value (:twitter, :displayName)';
            $statement = $this->connection->prepare($sql);
            $statement->bindParam(':twitter', $twitter_id);
            $statement->bindParam(':displayName', $displayName);
            $statement->execute($data);
        }
        catch(PDOException $e) {
            echo $e;
        }
        return $this->connection->lastInsertId();
    }

    public function createUserFacebook($facebook_id, $displayName){
        try {
            $data = array('facebook'=>$facebook_id, 'displayName'=>$displayName);
            $sql = 'INSERT INTO users (facebook, displayName) value (:facebook, :displayName)';
            $statement = $this->connection->prepare($sql);
            $statement->bindParam(':facebook_id', $facebook_id);
            $statement->bindParam(':displayName', $displayName);
            $statement->execute($data);
        }
        catch(PDOException $e) {
            echo $e;
        }
        return $this->connection->lastInsertId();
    }

    public function updateDisplayName($user_id, $displayName){
        try {
            $statement = $this->connection->prepare('UPDATE users SET displayName=:displayName WHERE id=:id');
            $statement->bindParam(':displayName', $displayName);
            $statement->bindParam(':id', $user_id);
            $statement->execute();
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function updateEmail($user_id, $email){
        try {
            $statement = $this->connection->prepare('UPDATE users SET email=:email WHERE id=:id');
            $statement->bindParam(':email', $email);
            $statement->bindParam(':id', $user_id);
            $statement->execute();
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function getAuthProvider($user_id){
        try {
            $statement = $this->connection->prepare('SELECT * FROM users WHERE id=:user_id');
            $statement->bindParam(':user_id', $user_id);
            $statement->execute();
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $results = $statement->fetchAll();
            if(count($results) === 1){
                if(!empty($results[0]['twitter'])){
                    return 'twitter';
                }
                if(!empty($results[0]['facebook'])){
                    return 'facebook';
                }   
                return 'local';
            }
            else {
                return null;
            }
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function getUserWithId($user_id){
        try {
            $statement = $this->connection->prepare('SELECT 
            id, 
            email, 
            displayName,
            facebook,
            foursquare,
            github,
            google,
            linkedin,
            twitter
            FROM users WHERE id=:user_id');
            $statement->bindParam(':user_id', $user_id);
            $statement->execute();
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $results = $statement->fetchAll();
            if(count($results) === 1){
                return $results[0];
            }
            else {
                return null;
            }
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function updateUser($user_id, $email, $displayName){
        try {
            if(empty($email)){
                $statement = $this->connection->prepare('UPDATE users SET displayName=:displayName WHERE id=:user_id');
                $statement->bindParam(':displayName', $displayName);
                $statement->bindParam(':user_id', $user_id);
                $statement->execute();
            }
            else {
                $statement = $this->connection->prepare('UPDATE users SET email=:email, displayName=:displayName WHERE id=:user_id');
                $statement->bindParam(':email', $email);
                $statement->bindParam(':displayName', $displayName);
                $statement->bindParam(':user_id', $user_id);
                $statement->execute();
            }

        }
        catch(PDOException $e){
            echo $e;
        }
    }

    public function getUserWithEmail($email){
        try {
            $statement = $this->connection->prepare('SELECT 
            id, 
            email, 
            displayName,
            facebook,
            foursquare,
            github,
            google,
            linkedin,
            twitter
            FROM users WHERE email=:email');
            $statement->bindParam(':email', $email);
            $statement->execute();
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $results = $statement->fetchAll();

            if(count($results) === 1){
                return $results[0];
            }
            else if(count($results) > 1){
                throw new MultipleUsersWithEmailException();
            }
            else {
                throw new UserNotFoundException();
            }
        }
        catch(PDOException $e) {
            echo $e;<commit_msg>Fixed faulty SQL statement.<commit_after><?php

Class UserModel extends Model{

    public function __construct($database){ 
        parent::__construct($database);
    }

    function __destruct() {
        parent::__destruct();
    }

    public function createUser($email, $password, $displayName){
        try {
            $data = array('email'=>$email, 'password'=>$password, 'displayName'=>$displayName);
            $sql = 'INSERT INTO users (email, password, displayName) value (:email, :password, :displayName)';
            $statement = $this->connection->prepare($sql);
            $statement->execute($data);
        }
        catch(PDOException $e) {
            echo $e;
        }
        return $this->connection->lastInsertId();
    }

    public function createUserTwitter($twitter_id, $displayName){
        try {
            $data = array('twitter'=>$twitter_id, 'displayName'=>$displayName);
            $sql = 'INSERT INTO users (twitter, displayName) value (:twitter, :displayName)';
            $statement = $this->connection->prepare($sql);
            $statement->bindParam(':twitter', $twitter_id);
            $statement->bindParam(':displayName', $displayName);
            $statement->execute($data);
        }
        catch(PDOException $e) {
            echo $e;
        }
        return $this->connection->lastInsertId();
    }

    public function createUserFacebook($facebook_id, $displayName){
        try {
            $data = array('facebook'=>$facebook_id, 'displayName'=>$displayName);
            $sql = 'INSERT INTO users (facebook, displayName) value (:facebook, :displayName)';
            $statement = $this->connection->prepare($sql);
            $statement->bindParam(':facebook_id', $facebook_id);
            $statement->bindParam(':displayName', $displayName);
            $statement->execute($data);
        }
        catch(PDOException $e) {
            echo $e;
        }
        return $this->connection->lastInsertId();
    }

    public function updateDisplayName($user_id, $displayName){
        try {
            $statement = $this->connection->prepare('UPDATE users SET displayName=:displayName WHERE id=:id');
            $statement->bindParam(':displayName', $displayName);
            $statement->bindParam(':id', $user_id);
            $statement->execute();
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function updateEmail($user_id, $email){
        try {
            $statement = $this->connection->prepare('UPDATE users SET email=:email WHERE id=:id');
            $statement->bindParam(':email', $email);
            $statement->bindParam(':id', $user_id);
            $statement->execute();
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function getAuthProvider($user_id){
        try {
            $statement = $this->connection->prepare('SELECT * FROM users WHERE id=:user_id');
            $statement->bindParam(':user_id', $user_id);
            $statement->execute();
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $results = $statement->fetchAll();
            if(count($results) === 1){
                if(!empty($results[0]['twitter'])){
                    return 'twitter';
                }
                if(!empty($results[0]['facebook'])){
                    return 'facebook';
                }   
                return 'local';
            }
            else {
                return null;
            }
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function getUserWithId($user_id){
        try {
            $statement = $this->connection->prepare('SELECT 
            id, 
            email, 
            displayName,
            facebook,
            foursquare,
            github,
            google,
            linkedin,
            twitter
            FROM users WHERE id=:user_id');
            $statement->bindParam(':user_id', $user_id);
            $statement->execute();
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $results = $statement->fetchAll();
            if(count($results) === 1){
                return $results[0];
            }
            else {
                return null;
            }
        }
        catch(PDOException $e) {
            echo $e;
        }
    }

    public function updateUser($user_id, $email, $displayName){
        try {
            if(empty($email)){
                $statement = $this->connection->prepare('UPDATE users SET displayName=:displayName WHERE id=:user_id');
                $statement->bindParam(':displayName', $displayName);
                $statement->bindParam(':user_id', $user_id);
                $statement->execute();
            }
            else {
                $statement = $this->connection->prepare('UPDATE users SET email=:email, displayName=:displayName WHERE id=:user_id');
                $statement->bindParam(':email', $email);
                $statement->bindParam(':displayName', $displayName);
                $statement->bindParam(':user_id', $user_id);
                $statement->execute();
            }

        }
        catch(PDOException $e){
            echo $e;
        }
    }

    public function getUserWithEmail($email){
        try {
            $statement = $this->connection->prepare('SELECT * FROM users WHERE email=:email');
            $statement->bindParam(':email', $email);
            $statement->execute();
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $results = $statement->fetchAll();

            if(count($results) === 1){
                return $results[0];
            }
            else if(count($results) > 1){
                throw new MultipleUsersWithEmailException();
            }
            else {
                throw new UserNotFoundException();
            }
        }
        catch(PDOException $e) {
            echo $e;
{'fraction_non_alphanumeric': 0.13807358412567178, 'fraction_numerical': 0.001322860686233981, 'mean_word_length': 1.7578659370725034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3780442', 'n_tokens_mistral': 3199, 'n_tokens_neox': 3072, 'n_words': 583}