Passed
Push — master ( 21e202...0aab8f )
by Petr
03:53
created

LinkRepository::findOneById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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