Passed
Pull Request — master (#500)
by Alejandro
06:23
created

PersistenceDomainResolver::resolveDomain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
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