Passed
Pull Request — master (#81)
by
unknown
04:01
created

WishlistRepository::findAllByAnonymous()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusWishlistPlugin\Repository;
12
13
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
14
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
15
use Sylius\Component\Core\Model\ShopUserInterface;
16
17
class WishlistRepository extends EntityRepository implements WishlistRepositoryInterface
18
{
19
    public function findOneByShopUser(ShopUserInterface $shopUser): ?WishlistInterface
20
    {
21
        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 BitBag\SyliusWishlistPlu...\WishlistInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
22
            ->where('o.shopUser = :shopUser')
23
            ->setParameter('shopUser', $shopUser)
24
            ->getQuery()
25
            ->getOneOrNullResult()
26
        ;
27
    }
28
29
    public function findByToken(string $token): ?WishlistInterface
30
    {
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 BitBag\SyliusWishlistPlu...\WishlistInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
32
            ->where('o.token = :token')
33
            ->setParameter('token', $token)
34
            ->getQuery()
35
            ->getOneOrNullResult()
36
        ;
37
    }
38
39
    public function findAllByShopUser(int $shopUser): ?array
40
    {
41
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
42
            ->where('o.shopUser = :shopUser')
43
            ->setParameter('shopUser', $shopUser)
44
            ->getQuery()
45
            ->getResult()
46
            ;
47
    }
48
49
    public function findAllByShopUserAndToken(int $shopUser, string $token): ?array
50
    {
51
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
52
            ->where('o.shopUser = :shopUser')
53
            ->orWhere('o.token = :token')
54
            ->setParameter('token', $token)
55
            ->setParameter('shopUser', $shopUser)
56
            ->getQuery()
57
            ->getResult()
58
            ;
59
    }
60
61
    public function findAllByAnonymous(?string $token): ?array
62
    {
63
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
64
            ->where('o.token = :token')
65
            ->andWhere('o.shopUser IS NULL')
66
            ->setParameter('token', $token)
67
            ->getQuery()
68
            ->getResult()
69
            ;
70
    }
71
}
72