Passed
Pull Request — master (#81)
by
unknown
13:39
created

WishlistRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneByShopUser() 0 7 1
A findByToken() 0 7 1
A findAllByShopUser() 0 7 1
A findAllByAnonymous() 0 6 1
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')
42
            ->where('o.shopUser = :shopUser')
43
            ->setParameter('shopUser', $shopUser)
44
            ->getQuery()
45
            ->getArrayResult()
46
            ;
47
    }
48
49
    public function findAllByAnonymous(?string $cookie): ?array
50
    {
51
        return $this->createQueryBuilder('o')
52
            ->where('o.shopUser is NULL')
53
            ->getQuery()
54
            ->getArrayResult()
55
            ;
56
    }
57
}
58