Completed
Push — symfony3-wololo ( 5670c9...50a832 )
by Kamil
20:37
created

AddressRepository::findByCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
13
14
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
15
use Sylius\Component\Core\Model\CustomerInterface;
16
use Sylius\Component\Core\Repository\AddressRepositoryInterface;
17
18
/**
19
 * @author Anna Walasek <[email protected]>
20
 * @author Jan Góralski <[email protected]>
21
 */
22
class AddressRepository extends EntityRepository implements AddressRepositoryInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function findByCustomer(CustomerInterface $customer)
28
    {
29
        return $this->createQueryBuilder('o')
30
            ->leftJoin('o.customer', 'customer')
31
            ->where('customer = :customer')
32
            ->setParameter('customer', $customer)
33
            ->getQuery()
34
            ->getResult()
35
        ;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function findOneByCustomer($id, CustomerInterface $customer)
42
    {
43
        return $this->createQueryBuilder('o')
44
            ->leftJoin('o.customer', 'customer')
45
            ->andWhere('o.id = :id')
46
            ->andWhere('customer = :customer')
47
            ->setParameter('id', $id)
48
            ->setParameter('customer', $customer)
49
            ->getQuery()
50
            ->getOneOrNullResult()
51
        ;
52
    }
53
}
54