Passed
Push — master ( 63b45b...921011 )
by Petr
04:21
created

LinkRepository::getOrCreateLink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace AppBundle\Entity\Repository;
4
5
use AppBundle\Entity\Infrasctucture\AbstractRepository;
6
use AppBundle\Entity\Link;
7
8
/** {@inheritDoc} */
9
class LinkRepository extends AbstractRepository
10
{
11
12
    /**
13
     * @return Link|object|null
14
     */
15 1
    public function findOneByUrl(string $linkUrl)
16
    {
17 1
        return $this->findOneBy(
18
            [
19 1
                'url' => $linkUrl,
20
            ]
21
        );
22
    }
23
24 1
    public function getOrCreateLink(string $url, string $description = null): Link
25
    {
26 1
        $link = $this->findOneByUrl($url);
27
28 1
        if (!$link) {
29 1
            $link = new Link($url, $description);
30
        }
31
32 1
        return $link;
33
    }
34
}
35