<commit_before><?php

namespace Muffin\Webservice;

use Cake\Datasource\QueryTrait;
use Cake\Utility\Hash;
use Muffin\Webservice\Model\Endpoint;
use Muffin\Webservice\Webservice\WebserviceInterface;

class Query
{

    use QueryTrait;

    const ACTION_CREATE = 1;
    const ACTION_READ = 2;
    const ACTION_UPDATE = 3;
    const ACTION_DELETE = 4;

    /**
     * Indicates that the operation should append to the list
     *
     * @var int
     */
    const APPEND = 0;

    /**
     * Indicates that the operation should prepend to the list
     *
     * @var int
     */
    const PREPEND = 1;

    /**
     * Indicates that the operation should overwrite the list
     *
     * @var bool
     */
    const OVERWRITE = true;

    /**
     * Indicates whether internal state of this query was changed, this is used to
     * discard internal cached objects such as the transformed query or the reference
     * to the executed statement.
     *
     * @var bool
     */
    protected $_dirty = false;

    private $_action;
    private $_conditions = [];
    private $_page;
    private $_limit;
    private $_fields = [];
    private $_order = [];

    /**
     * @var \Muffin\Webservice\Webservice\WebserviceInterface
     */
    protected $_webservice;

    /**
     * @var ResultSet
     */
    protected $_resultSet;

    public function __construct(WebserviceInterface $webservice, Endpoint $endpoint)
    {
        $this->_webservice = $webservice;
        $this->endpoint($endpoint);
    }

    public function create()
    {
        $this->action(self::ACTION_CREATE);

        return $this;
    }

    public function read()
    {
        $this->action(self::ACTION_READ);

        return $this;
    }

    public function update()
    {
        $this->action(self::ACTION_UPDATE);

        return $this;
    }

    public function delete()
    {
        $this->action(self::ACTION_DELETE);

        return $this;
    }

    /**
     * @param Endpoint|null $endpoint
     * @return Endpoint|$this
     */
    public function endpoint(Endpoint $endpoint = null)
    {
        if ($endpoint === null) {
            return $this->repository();
        }

        $this->repository($endpoint);

        return $this;
    }

    public function aliasField($field)
    {
        return [$field => $field];
    }

    /**
     * @param null $conditions
     * @param array $types
     * @param bool|false $overwrite
     *
     * @return $this|array|Query
     */
    public function where($conditions = null, $types = [], $overwrite = false)
    {
        if ($conditions === null) {
            return $this->_conditions;
        }
<commit_msg>Override firstOrFail because Endpoints don't use tables<commit_after><?php

namespace Muffin\Webservice;

use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Datasource\QueryTrait;
use Cake\Utility\Hash;
use Muffin\Webservice\Model\Endpoint;
use Muffin\Webservice\Webservice\WebserviceInterface;

class Query
{

    use QueryTrait;

    const ACTION_CREATE = 1;
    const ACTION_READ = 2;
    const ACTION_UPDATE = 3;
    const ACTION_DELETE = 4;

    /**
     * Indicates that the operation should append to the list
     *
     * @var int
     */
    const APPEND = 0;

    /**
     * Indicates that the operation should prepend to the list
     *
     * @var int
     */
    const PREPEND = 1;

    /**
     * Indicates that the operation should overwrite the list
     *
     * @var bool
     */
    const OVERWRITE = true;

    /**
     * Indicates whether internal state of this query was changed, this is used to
     * discard internal cached objects such as the transformed query or the reference
     * to the executed statement.
     *
     * @var bool
     */
    protected $_dirty = false;

    private $_action;
    private $_conditions = [];
    private $_page;
    private $_limit;
    private $_fields = [];
    private $_order = [];

    /**
     * @var \Muffin\Webservice\Webservice\WebserviceInterface
     */
    protected $_webservice;

    /**
     * @var ResultSet
     */
    protected $_resultSet;

    public function __construct(WebserviceInterface $webservice, Endpoint $endpoint)
    {
        $this->_webservice = $webservice;
        $this->endpoint($endpoint);
    }

    public function create()
    {
        $this->action(self::ACTION_CREATE);

        return $this;
    }

    public function read()
    {
        $this->action(self::ACTION_READ);

        return $this;
    }

    public function update()
    {
        $this->action(self::ACTION_UPDATE);

        return $this;
    }

    public function delete()
    {
        $this->action(self::ACTION_DELETE);

        return $this;
    }

    /**
     * @param Endpoint|null $endpoint
     * @return Endpoint|$this
     */
    public function endpoint(Endpoint $endpoint = null)
    {
        if ($endpoint === null) {
            return $this->repository();
        }

        $this->repository($endpoint);

        return $this;
    }

    /**
     * Get the first result from the executing query or raise an exception.
     *
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When there is no first record.
     *
     * @return mixed The first result from the ResultSet.
     */
    public function firstOrFail()
    {
        $entity = $this->first();
        if ($entity) {
            return $entity;
        }
        throw new RecordNotFoundException(sprintf(
            'Record not found in endpoint "%s"',
            $this->repository()->endpoint()
        ));
    }

    public function aliasField($field)
    {
        return [$field => $field];
    }

    /**
     * @param null $conditions
     * @param array $types
     * @param bool|false $overwrite
     *
     * @return $this|array|Query
     */
    public function where($conditions = null, $types = [], $overwrite = false)
    {
        if ($conditions === null) {
            return $this->_conditions;
        }

{'fraction_non_alphanumeric': 0.1108316566063045, 'fraction_numerical': 0.002012072434607646, 'mean_word_length': 2.1019240769630785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '2586310', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1662, 'n_words': 459}