<commit_before><?php
declare(strict_types=1);

namespace AppBundle\Repository;


use AppBundle\Entity\Picture;
use AppBundle\Entity\Tag;
use AppBundle\Model\Status;

/**
 * Class PictureRepository
 * @package AppBundle\Repository
 */
class PictureRepository extends \Doctrine\ORM\EntityRepository
{
    /**
     * Find duplicates for given picture
     * @param Picture $picture
     * @return Picture|null
     */
    public function findDuplicates(Picture $picture) : ?Picture
    {
        $md5 = $picture->getMd5sum();
        $sha1 = $picture->getSha1sum();

        return $this->createQueryBuilder('p')
            ->where('(p.md5sum = :md5 OR p.sha1sum = :sha1)')
            ->andWhere('p.status = :status')
            ->setParameter('md5', $md5)
            ->setParameter('sha1', $sha1)
            ->setParameter('status', Status::OK)
            ->getQuery()
            ->getOneOrNullResult();
    }

    /**
     * Return a picture without tag
     * @return Picture|null
     */
    public function getPictureWithoutTags() : ?Picture
    {
        return $this->createQueryBuilder('p')
            ->leftJoin('p.tags', 't')
            ->where('t.id IS NULL')
            ->andWhere('p.status = :status')
            ->setParameter('status', Status::OK)
            ->orderBy('RAND()')
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }

    /**
     * Return all pictures belonging to this tag
     * @param Tag $tag
     * @return array
     */
    public function findRandomByTag(Tag $tag) : array
    {
        $query = $this->createQueryBuilder('p');
        $query->join('p.tags', 't')
            ->where($query->expr()->eq('t.id', $tag->getId()))
            ->setMaxResults(50);
        return $query->getQuery()->getResult();
    }

    /**
     * Return 50 random pictures
     * @return array
     */
    public function findRandom() : array
    {
        $query = $this->createQueryBuilder('p')
            ->orderBy('rand')
            ->setMaxResults(50);

        return $query->getQuery()->getResult();<commit_msg>Fix RAND()<commit_after><?php
declare(strict_types=1);

namespace AppBundle\Repository;


use AppBundle\Entity\Picture;
use AppBundle\Entity\Tag;
use AppBundle\Model\Status;

/**
 * Class PictureRepository
 * @package AppBundle\Repository
 */
class PictureRepository extends \Doctrine\ORM\EntityRepository
{
    /**
     * Find duplicates for given picture
     * @param Picture $picture
     * @return Picture|null
     */
    public function findDuplicates(Picture $picture) : ?Picture
    {
        $md5 = $picture->getMd5sum();
        $sha1 = $picture->getSha1sum();

        return $this->createQueryBuilder('p')
            ->where('(p.md5sum = :md5 OR p.sha1sum = :sha1)')
            ->andWhere('p.status = :status')
            ->setParameter('md5', $md5)
            ->setParameter('sha1', $sha1)
            ->setParameter('status', Status::OK)
            ->getQuery()
            ->getOneOrNullResult();
    }

    /**
     * Return a picture without tag
     * @return Picture|null
     */
    public function getPictureWithoutTags() : ?Picture
    {
        return $this->createQueryBuilder('p')
            ->leftJoin('p.tags', 't')
            ->where('t.id IS NULL')
            ->andWhere('p.status = :status')
            ->setParameter('status', Status::OK)
            ->orderBy('RAND()')
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }

    /**
     * Return all pictures belonging to this tag
     * @param Tag $tag
     * @return array
     */
    public function findRandomByTag(Tag $tag) : array
    {
        $query = $this->createQueryBuilder('p');
        $query->join('p.tags', 't')
            ->where($query->expr()->eq('t.id', $tag->getId()))
            ->setMaxResults(50);
        return $query->getQuery()->getResult();
    }

    /**
     * Return 50 random pictures
     * @return array
     */
    public function findRandom() : array
    {
        $query = $this->createQueryBuilder('p')
            ->orderBy('RAND()')
            ->setMaxResults(50);

        return $query->getQuery()->getResult();
{'fraction_non_alphanumeric': 0.15707806158987825, 'fraction_numerical': 0.009548818333731201, 'mean_word_length': 2.1362275449101795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '2758772', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1215, 'n_words': 244}