<commit_before><?php
namespace Cinder;

/**
 * Class Cinder
 * 
 * @author Chareice <<EMAIL>>
 */
class Cinder{
    private static $_options = NULL;

    private static function tableStmt(){
        return "`".self::$_options['table']."`";
    }

    private static function setOptions($options){
        self::$_options = $options;
    }

    private static function orderStmt(){
        if(isset(self::$_options['order'])){
            return " order by ".self::$_options['order'];
        }
        return "";
    }

    private static function limitStmt(){
        if(isset(self::$_options['limit'])){
            $stmt = " limit ".self::$_options['limit'];
            
            if(isset(self::$_options['offset'])){
                $stmt .= " offset ".self::$_options['offset'];
            }
            return $stmt;
        }
        return "";
    }

    private static function isLimitOne(){
         if(isset(self::$_options['limit'])){
            if(self::$_options['limit'] == 1){
                return true;
            }
         }
         return false;
    }
    
    public static function getInstance($options){
        $_isNew = isset($options['value']) ? false : true;

        $options['primary'] = isset($options['primary']) ? $options['primary'] : "id";
        $options['field'] = isset($options['field']) ? $options['field'] : $options['primary'];

        self::setOptions($options);

        $db = DBC::getInstance();

        if($_isNew){
            return new ORM($options);
        }else{
            /**
            * select row count from database
            */
            if(isset($options['like'])){
                $like = true;
                $sql = "select count(*) as count from ".self::tableStmt()." where `{$options['field']}` like :{$options['field']}";
                $stmt = $db->prepare($sql);
                $stmt->bindValue(":".$options['field'],"%".$options['value']."%");
            }else{
                $sql = "select count(*) as count from ".self::tableStmt()." where `{$options['field']}` = :{$options['field']}";
                $stmt = $db->prepare($sql);
                $stmt->bindValue($options['field'],$options['value']);
            }

            $stmt->execute();
            $count = $stmt->fetchColumn();

            if($count > 1){
                /**
                * If row count greater than one,will return an Array consist of ORM Object
                */
                $orms = array();
                if(isset($options['like'])){
                    $sql = "select `{$options['primary']}` from ".self::tableStmt()." where `{$options['field']}` like :{$options['field']}".self::orderStmt().self::limitStmt();
                    $stmt = $db->prepare($sql);
                    $stmt->bindValue($options['field'],"%{$options['value']}%");
                }else{
                    $sql = "select `{$options['primary']}` from ".self::tableStmt()." where `{$options['field']}`= :{$options['field']}".self::orderStmt().self::limitStmt();
                    $stmt = $db->prepare($sql);
                    $stmt->bindValue($options['field'],$options['value']);
                }

                $stmt->execute();
                
                $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);

                foreach ($result as $row) {
                    $orm = new ORM($options);
                    $orm->load($row[$options['primary']],$options['primary']);
                    array_push($orms, $orm);
                }
                return $orms;
            }else if($count == 1){
                $orm = new ORM($options);
                $orm->load($options['value'],$options['field']);
                return $orm;
            }else{
                throw new \Exception("Error disappre when create Cinder", 1);
            }
        }
    }<commit_msg>Fix the logic when get instance form cinder object,now it aways return a ORM array no matter the result of sql fetch<commit_after><?php
namespace Cinder;

/**
 * Class Cinder
 * 
 * @author Chareice <<EMAIL>>
 */
class Cinder{
    private static $_options = NULL;

    private static function tableStmt(){
        return "`".self::$_options['table']."`";
    }

    private static function setOptions($options){
        self::$_options = $options;
    }

    private static function orderStmt(){
        if(isset(self::$_options['order'])){
            return " order by ".self::$_options['order'];
        }
        return "";
    }

    private static function limitStmt(){
        if(isset(self::$_options['limit'])){
            $stmt = " limit ".self::$_options['limit'];
            
            if(isset(self::$_options['offset'])){
                $stmt .= " offset ".self::$_options['offset'];
            }
            return $stmt;
        }
        return "";
    }

    private static function isLimitOne(){
         if(isset(self::$_options['limit'])){
            if(self::$_options['limit'] == 1){
                return true;
            }
         }
         return false;
    }
    
    public static function getInstance($options){
        $_isNew = isset($options['value']) ? false : true;

        $options['primary'] = isset($options['primary']) ? $options['primary'] : "id";
        $options['field'] = isset($options['field']) ? $options['field'] : $options['primary'];

        self::setOptions($options);

        $db = DBC::getInstance();

        if($_isNew){
            return new ORM($options);
        }else{
            $orms = array();
            if(isset($options['like'])){
                $sql = "select `{$options['primary']}` from ".self::tableStmt()." where `{$options['field']}` like :{$options['field']}".self::orderStmt().self::limitStmt();
                $stmt = $db->prepare($sql);
                $stmt->bindValue($options['field'],"%{$options['value']}%");
            }else{
                $sql = "select `{$options['primary']}` from ".self::tableStmt()." where `{$options['field']}`= :{$options['field']}".self::orderStmt().self::limitStmt();
                $stmt = $db->prepare($sql);
                $stmt->bindValue($options['field'],$options['value']);
            }

            $stmt->execute();
            
            $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);

            foreach ($result as $row) {
                $orm = new ORM($options);
                $orm->load($row[$options['primary']],$options['primary']);
                array_push($orms, $orm);
            }
            return $orms;
        }
    }
{'fraction_non_alphanumeric': 0.187356497780499, 'fraction_numerical': 0.000765345170671973, 'mean_word_length': 1.913062862238074, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 29, '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': '6309604', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1742, 'n_words': 349}