Passed
Push — master ( 921011...5d9034 )
by Petr
04:49
created

LinkRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneByUrl() 0 8 1
A getOrCreateLink() 0 10 2
A findOneById() 0 4 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
    /**
36
     * @return Link|object|null
37
     */
38 1
    public function findOneById(string $linkId)
39
    {
40 1
        return $this->find($linkId);
41
    }
42
}
43