Completed
Push — master ( 674d5a...194be7 )
by Gorka
04:12
created

organizationOfSlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Infrastructure\Persistence\Doctrine\ORM\Organization;
16
17
use Doctrine\ORM\EntityRepository;
18
use Kreta\SharedKernel\Domain\Model\Identity\Slug;
19
use Kreta\TaskManager\Domain\Model\Organization\Organization;
20
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
21
use Kreta\TaskManager\Domain\Model\Organization\OrganizationRepository;
22
23
class DoctrineORMOrganizationRepository extends EntityRepository implements OrganizationRepository
24
{
25
    public function organizationOfId(OrganizationId $id)
26
    {
27
        return $this->find($id->id());
28
    }
29
30
    public function organizationOfSlug(Slug $slug)
31
    {
32
        return $this->findOneBy(['slug.slug' => $slug->slug()]);
33
    }
34
35
    public function query($specification)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
    {
37
        return null === $specification
38
            ? $this->findAll()
39
            : $specification->buildQuery($this->getEntityManager()->createQueryBuilder())->getResult();
40
    }
41
42
    public function persist(Organization $organization)
43
    {
44
        $this->getEntityManager()->persist($organization);
45
    }
46
47
    public function remove(Organization $organization)
48
    {
49
        $this->getEntityManager()->remove($organization);
50
    }
51
52
    public function count($specification) : int
53
    {
54
        if (null === $specification) {
55
            $queryBuilder = $this->createQueryBuilder('o');
56
57
            return (int) $queryBuilder
58
                ->select($queryBuilder->expr()->count('o.id'))
59
                ->getQuery()
60
                ->getSingleScalarResult();
61
        }
62
63
        return (int) $specification->buildCount(
64
            $this->getEntityManager()->createQueryBuilder()
65
        )->getSingleScalarResult();
66
    }
67
}
68