findOneByAffiliateNotExpired()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusReferralsPlugin\Repository;
6
7
use Odiseo\SyliusReferralsPlugin\Entity\AffiliateInterface;
8
use Odiseo\SyliusReferralsPlugin\Entity\AffiliateReferralInterface;
9
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
10
use Sylius\Component\Core\Model\ProductInterface;
11
12
class AffiliateReferralRepository extends EntityRepository implements AffiliateReferralRepositoryInterface
13
{
14
    public function findOneByAffiliateNotExpired(AffiliateInterface $affiliate): ?AffiliateReferralInterface
15
    {
16
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...)->getOneOrNullResult() could return the type integer which is incompatible with the type-hinted return Odiseo\SyliusReferralsPl...eReferralInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
17
            ->andWhere('o.affiliate = :affiliate')
18
            ->andWhere('o.product IS NULL')
19
            ->andWhere('o.expiresAt IS NULL')
20
            ->setParameter('affiliate', $affiliate)
21
            ->setMaxResults(1)
22
            ->getQuery()
23
            ->getOneOrNullResult()
24
        ;
25
    }
26
27
    public function findOneByAffiliateAndProductNotExpired(
28
        AffiliateInterface $affiliate,
29
        ProductInterface $product,
30
    ): ?AffiliateReferralInterface {
31
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...)->getOneOrNullResult() could return the type integer which is incompatible with the type-hinted return Odiseo\SyliusReferralsPl...eReferralInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
32
            ->andWhere('o.affiliate = :affiliate')
33
            ->andWhere('o.product = :product')
34
            ->andWhere('o.expiresAt > :now')
35
            ->setParameter('product', $product)
36
            ->setParameter('affiliate', $affiliate)
37
            ->setParameter('now', new \DateTime())
38
            ->setMaxResults(1)
39
            ->getQuery()
40
            ->getOneOrNullResult()
41
        ;
42
    }
43
}
44