Completed
Push — master ( a81ac8...05e307 )
by Alejandro
25s queued 13s
created

PersistenceDomainResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Domain\Resolver;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use Shlinkio\Shlink\Core\Entity\Domain;
8
9
class PersistenceDomainResolver implements DomainResolverInterface
10
{
11
    /** @var EntityManagerInterface */
12
    private $em;
13
14 6
    public function __construct(EntityManagerInterface $em)
15
    {
16 6
        $this->em = $em;
17
    }
18
19 6
    public function resolveDomain(?string $domain): ?Domain
20
    {
21 6
        if ($domain === null) {
22 4
            return null;
23
        }
24
25
        /** @var Domain|null $existingDomain */
26 2
        $existingDomain = $this->em->getRepository(Domain::class)->findOneBy(['authority' => $domain]);
27 2
        return $existingDomain ?? new Domain($domain);
28
    }
29
}
30