<commit_before><?php
namespace Bob\Phalcon;

class Fetch
{
    /**
     * @var \Phalcon\Di
     */
    protected $_di;

    protected $patch;

    protected $request;

    protected $redis;

    protected $namespaces = array();

    protected $modes   = array();

    protected $patches = array();

    /**
     * default page number
     *
     * @var int
     */
    private $page = 1;

    /**
     * default limit
     *
     * @var int
     */
    private $limit = 10;
    
    public function __construct(\Phalcon\Di $di)
    {
        $this->_di = $di;
        $this->patch = $di->get('patch');
        $this->redis = $di->get('cache');
        $this->request = $di->get('request');
    }

    public function attach($action)
    {
        $this->modes[$action] = true;
    }

    public function __get($name)
    {
        $this->namespaces[] = $name;
        return $this;
    }

    public function setNamespace($name)
    {
        $this->namespaces[] = $name;
    }

    public function getNamespace()
    {
        return $this->namespaces;
    }

    /**
     * Create new model
     *
     * @param $data
     * @return \Bob\Phalcon\Definition\Model\Collection|bool
     * @throws \Bob\Phalcon\Exception\Saved
     */
    public function create($data)
    {
        $thrown = $this->hasThrown();
        $class  = $this->getClass();
        $model  = new $class();

        foreach($data as $k => $v) {
            if(property_exists($model, $k))
                $model->$k = $v;
        }

        if(!$model->save()) {
            if($thrown) throw new \Bob\Phalcon\Exception\Saved($model);
            return false;
        }
        return $model;
    }

    /**
     * Update model
     *
     * @param \Bob\Phalcon\Definition\Model\Collection $model
     * @param Collection $data
     * @return bool
     * @throws \Bob\Phalcon\Exception\Saved
     */
    public function update(\Bob\Phalcon\Definition\Model\Collection $model, Collection $data)
    {
        $thrown = $this->hasThrown();

        foreach($data as $k => $v) {
            if(property_exists($model, $k))
                $model->$k = $v;
        }

        $this->initNS();

        if(!$model->save()) {
            if($thrown) throw new \Bob\Phalcon\Exception\Saved($model);
            return false;
        }
        return true;
    }

    private function initNS()
    {
        $this->namespaces = [];
    }

    /**
     * @param \Bob\Phalcon\Definition\Model\Collection $model
     * @return bool
     * @throws \Bob\Phalcon\Exception\Saved
     */
    public function delete(\Bob\Phalcon\Definition\Model\Collection $model)
    {
        $thrown = $this->hasThrown();

        $this->initNS();

        if(!$model->delete()) {
            if($thrown) throw new \Bob\Phalcon\Exception\Saved($model);
            return false;
        }
        return true;
    }

    /**
     * @param $id
     * @param array $pair
     * @throws \Bob\Phalcon\Exception\Increment
     */
    public function incr($id, array $pair)
    {
        $class = $this->getClass();
        $self = new $class();
        $col = $self->getCollection();

        $cond['_id'] = new \MongoId($id);

        foreach($pair as $k => $v) ;
        $cond = ['_id' => new \MongoId($id)];
        if ($v < 0) $cond[$k] = ['$gte' => abs($v)];

        $ret = $col->update($cond, array('$inc' => array($k => $v)));
        if(!$ret) throw new \Bob\Phalcon\Exception\Increment($class, $pair);

        $this->redis->delete($class . RDS . $id);
    }

    /**
     * @param $id
     * @param array $pair
     * @throws \Bob\Phalcon\Exception\Increment
     */
    public function decr($id, array $pair)
    {
        $class = $this->getClass();
        $self = new $class();
        $col = $self->getCollection();

        $cond['_id'] = new \MongoId($id);

        foreach($pair as $k => $v) ;
        $cond = ['_id' => new \MongoId($id)];

        $ret = $col->update($cond, array('$inc' => array($k => -abs($v))));
        if(!$ret) throw new \Bob\Phalcon\Exception\Increment($class, $pair);

        $this->redis->delete($class . RDS . $id);
    }
<commit_msg>Removed decr() due to feel repeat with incr() - Changed behavior of incr() can be affected with `thrown` label now.<commit_after><?php
namespace Bob\Phalcon;

class Fetch
{
    /**
     * @var \Phalcon\Di
     */
    protected $_di;

    protected $patch;

    protected $request;

    protected $redis;

    protected $namespaces = array();

    protected $modes   = array();

    protected $patches = array();

    /**
     * default page number
     *
     * @var int
     */
    private $page = 1;

    /**
     * default limit
     *
     * @var int
     */
    private $limit = 10;
    
    public function __construct(\Phalcon\Di $di)
    {
        $this->_di = $di;
        $this->patch = $di->get('patch');
        $this->redis = $di->get('cache');
        $this->request = $di->get('request');
    }

    public function attach($action)
    {
        $this->modes[$action] = true;
    }

    public function __get($name)
    {
        $this->namespaces[] = $name;
        return $this;
    }

    public function setNamespace($name)
    {
        $this->namespaces[] = $name;
    }

    public function getNamespace()
    {
        return $this->namespaces;
    }

    /**
     * Create new model
     *
     * @param $data
     * @return \Bob\Phalcon\Definition\Model\Collection|bool
     * @throws \Bob\Phalcon\Exception\Saved
     */
    public function create($data)
    {
        $thrown = $this->hasThrown();
        $class  = $this->getClass();
        $model  = new $class();

        foreach($data as $k => $v) {
            if(property_exists($model, $k))
                $model->$k = $v;
        }

        if(!$model->save()) {
            if($thrown) throw new \Bob\Phalcon\Exception\Saved($model);
            return false;
        }
        return $model;
    }

    /**
     * Update model
     *
     * @param \Bob\Phalcon\Definition\Model\Collection $model
     * @param Collection $data
     * @return bool
     * @throws \Bob\Phalcon\Exception\Saved
     */
    public function update(\Bob\Phalcon\Definition\Model\Collection $model, Collection $data)
    {
        $thrown = $this->hasThrown();

        foreach($data as $k => $v) {
            if(property_exists($model, $k))
                $model->$k = $v;
        }

        $this->initNS();

        if(!$model->save()) {
            if($thrown) throw new \Bob\Phalcon\Exception\Saved($model);
            return false;
        }
        return true;
    }

    private function initNS()
    {
        $this->namespaces = [];
    }

    /**
     * @param \Bob\Phalcon\Definition\Model\Collection $model
     * @return bool
     * @throws \Bob\Phalcon\Exception\Saved
     */
    public function delete(\Bob\Phalcon\Definition\Model\Collection $model)
    {
        $thrown = $this->hasThrown();

        $this->initNS();

        if(!$model->delete()) {
            if($thrown) throw new \Bob\Phalcon\Exception\Saved($model);
            return false;
        }
        return true;
    }

    /**
     * @param $id
     * @param array $pair
     * @throws \Bob\Phalcon\Exception\Increment
     */
    public function incr($id, array $pair)
    {
        $thrown = $this->hasThrown();
        $class = $this->getClass();
        $self = new $class();
        $col = $self->getCollection();

        $cond['_id'] = new \MongoId($id);

        foreach($pair as $k => $v) ;
        $cond = ['_id' => new \MongoId($id)];

        $ret = $col->update($cond, array('$inc' => array($k => -abs($v))));
        if(!$ret && $thrown) throw new \Bob\Phalcon\Exception\Increment($class, $pair);

        $this->redis->delete($class . RDS . $id);
    }

{'fraction_non_alphanumeric': 0.16806505744159028, 'fraction_numerical': 0.0009035755776429585, 'mean_word_length': 1.8236151603498543, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 82, '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': '6919822', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2471, 'n_words': 504}