Lines 100.00% 7 / 7
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
DoneBannerRepository 100.00% 7 / 7 100.00% 3 / 3 3 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 findByOwner 100.00% 1 / 1 100.00% 1 / 1 1
 findDatedByOwner 100.00% 5 / 5 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Repository;
6
7use App\Entity\DoneBanner;
8use App\Entity\User;
9use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
10use Doctrine\Common\Collections\Criteria;
11use Doctrine\Common\Collections\Order;
12use Doctrine\Persistence\ManagerRegistry;
13
14/**
15 * @extends ServiceEntityRepository<DoneBanner>
16 */
17class DoneBannerRepository extends ServiceEntityRepository
18{
19    public function __construct(ManagerRegistry $registry)
20    {
21        parent::__construct($registry, DoneBanner::class);
22    }
23
24    /**
25     * @return list<DoneBanner> newest on the done list first
26     */
27    public function findByOwner(User $owner): array
28    {
29        return $this->findBy(['owner' => $owner], ['position' => 'ASC']);
30    }
31
32    /**
33     * @return list<DoneBanner> those with a day, newest first
34     */
35    public function findDatedByOwner(User $owner): array
36    {
37        $criteria = Criteria::create()
38            ->where(Criteria::expr()->eq('owner', $owner))
39            ->andWhere(Criteria::expr()->neq('doneAt', null))
40            ->orderBy(['doneAt' => Order::Descending, 'position' => Order::Ascending]);
41
42        return \array_values($this->matching($criteria)->toArray());
43    }
44}