Passed
Push — master ( a403c4...843515 )
by Diego
07:39 queued 01:51
created

AffiliateRepository::findOneByCustomerNotExpired()   A

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 Sylius\Component\Core\Model\CustomerInterface;
9
use Sylius\Component\Core\Model\ProductInterface;
10
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
11
12
class AffiliateRepository extends EntityRepository implements AffiliateRepositoryInterface
13
{
14
    public function findOneByCustomerNotExpired(CustomerInterface $customer): ?AffiliateInterface
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...AffiliateInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
17
            ->andWhere('o.customer = :customer')
18
            ->andWhere('o.product IS NULL')
19
            ->andWhere('o.expiresAt IS NULL')
20
            ->setParameter('customer', $customer)
21
            ->setMaxResults(1)
22
            ->getQuery()
23
            ->getOneOrNullResult()
24
        ;
25
    }
26
27
    public function findOneByCustomerAndProductNotExpired(
28
        CustomerInterface $customer,
29
        ProductInterface $product
30
    ): ?AffiliateInterface {
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...AffiliateInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
32
            ->andWhere('o.customer = :customer')
33
            ->andWhere('o.product = :product')
34
            ->andWhere('o.expiresAt > :now')
35
            ->setParameter('product', $product)
36
            ->setParameter('customer', $customer)
37
            ->setParameter('now', new \DateTime())
38
            ->setMaxResults(1)
39
            ->getQuery()
40
            ->getOneOrNullResult()
41
        ;
42
    }
43
}
44