<commit_before><?php

namespace Synapse\Mapper;

use InvalidArgumentException;
use LogicException;
use Synapse\Mapper\PaginationData;
use Synapse\Stdlib\Arr;
use Synapse\Entity\EntityIterator;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\PreparableSqlInterface;
use Zend\Db\Sql\Predicate\Like;
use Zend\Db\Sql\Predicate\NotLike;
use Zend\Db\Sql\Predicate\Operator;
use Zend\Db\Sql\Predicate\In;

/**
 * Use this trait to add find functionality to AbstractMappers.
 */
trait FinderTrait
{
    /**
     * Default maximum number of results to return if pagination is used
     *
     * @var integer
     */
    protected $resultsPerPage = 50;

    /**
     * Set maximum number of results to return if pagination is enabled
     *
     * @param int $resultsPerPage
     */
    public function setResultsPerPage($resultsPerPage)
    {
        $this->resultsPerPage = $resultsPerPage;
    }

    /**
     * Find a single entity by specific field values
     *
     * @param  array  $wheres An array of where conditions in the format:
     *                        ['column' => 'value'] or
     *                        ['column', 'operator', 'value']
     * @param  array  $options
     * @return AbstractEntity|bool
     */
    public function findBy(array $wheres, array $options = [])
    {
        $query = $this->getSqlObject()->select();

        $this->setColumns($query, $options);

        $wheres = $this->addJoins($query, $wheres);

        $this->addWheres($query, $wheres, $options);

        return $this->executeAndGetResultsAsEntity($query);
    }

    /**
     * Find a single entity by ID
     *
     * @param  int|string $id Entity ID
     * @return AbstractEntity|bool
     */
    public function findById($id)
    {
        return $this->findBy(['id' => $id]);
    }

    /**
     * Find all entities matching specific field values
     *
     * @param  array $wheres  An array of where conditions in the format:
     *                        ['column' => 'value'] or
     *                        ['column', 'operator', 'value']
     * @param  array $options Array of options for this request.
     *                        May include 'order', 'page', or 'resultsPerPage'.
     * @return array          Array of AbstractEntity objects<commit_msg>Refs #129 - added the optiosn param<commit_after><?php

namespace Synapse\Mapper;

use InvalidArgumentException;
use LogicException;
use Synapse\Mapper\PaginationData;
use Synapse\Stdlib\Arr;
use Synapse\Entity\EntityIterator;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\PreparableSqlInterface;
use Zend\Db\Sql\Predicate\Like;
use Zend\Db\Sql\Predicate\NotLike;
use Zend\Db\Sql\Predicate\Operator;
use Zend\Db\Sql\Predicate\In;

/**
 * Use this trait to add find functionality to AbstractMappers.
 */
trait FinderTrait
{
    /**
     * Default maximum number of results to return if pagination is used
     *
     * @var integer
     */
    protected $resultsPerPage = 50;

    /**
     * Set maximum number of results to return if pagination is enabled
     *
     * @param int $resultsPerPage
     */
    public function setResultsPerPage($resultsPerPage)
    {
        $this->resultsPerPage = $resultsPerPage;
    }

    /**
     * Find a single entity by specific field values
     *
     * @param  array  $wheres An array of where conditions in the format:
     *                        ['column' => 'value'] or
     *                        ['column', 'operator', 'value']
     * @param  array  $options
     * @return AbstractEntity|bool
     */
    public function findBy(array $wheres, array $options = [])
    {
        $query = $this->getSqlObject()->select();

        $this->setColumns($query, $options);

        $wheres = $this->addJoins($query, $wheres, $options);

        $this->addWheres($query, $wheres, $options);

        return $this->executeAndGetResultsAsEntity($query);
    }

    /**
     * Find a single entity by ID
     *
     * @param  int|string $id Entity ID
     * @return AbstractEntity|bool
     */
    public function findById($id)
    {
        return $this->findBy(['id' => $id]);
    }

    /**
     * Find all entities matching specific field values
     *
     * @param  array $wheres  An array of where conditions in the format:
     *                        ['column' => 'value'] or
     *                        ['column', 'operator', 'value']
     * @param  array $options Array of options for this request.
     *                        May include 'order', 'page', or 'resultsPerPage'.
     * @return array          Array of AbstractEntity objects
{'fraction_non_alphanumeric': 0.1156043956043956, 'fraction_numerical': 0.0015384615384615385, 'mean_word_length': 2.2670495333811918, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '650921', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1287, 'n_words': 371}