Passed
Push — master ( ab171b...3e1bb9 )
by Philip
14:43
created

TransactionalUuidCrudRepository::findByUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Dontdrinkandroot\Repository;
4
5
use Doctrine\ORM\Query;
6
7
/**
8
 * @author Philip Washington Sorst <[email protected]>
9
 */
10
class TransactionalUuidCrudRepository extends TransactionalCrudRepository implements UuidCrudRepositoryInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 6
    public function findByUuid(string $uuid): ?object
16
    {
17 6
        return $this->getTransactionManager()->transactional(
18
            function () use ($uuid) {
19 6
                $query = $this->createFindByUuidQuery($uuid);
20
21 6
                return $query->getOneOrNullResult();
22 6
            }
23
        );
24
    }
25
26 6
    protected function createFindByUuidQuery(string $uuid): Query
27
    {
28 6
        $queryBuilder = $this->createQueryBuilder('entity');
29 6
        $queryBuilder->where('entity.uuid = :uuid');
30 6
        $queryBuilder->setParameter('uuid', $uuid);
31
32 6
        return $queryBuilder->getQuery();
33
    }
34
}
35