Completed
Push — master ( e1cfbf...f5d5d5 )
by Joachim
04:22
created

TerminalRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findTerminalByTitle() 0 15 2
A findTerminalBySlug() 0 15 2
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Entity;
4
5
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
6
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
7
8
class TerminalRepository extends EntityRepository implements ContainerAwareInterface
9
{
10
    use ContainerAwareTrait;
11
12
    /**
13
     * @param string $title
14
     * @param bool   $fetch
15
     *
16
     * @return Terminal|null
17
     */
18
    public function findTerminalByTitle(string $title, $fetch = false): ?Terminal
19
    {
20
        /** @var Terminal $terminal */
21
        $terminal = $this->findOneBy([
22
            'title' => $title,
23
        ]);
24
25
        if ($fetch) {
26
            $this->container->get('loevgaard_dandomain_altapay.terminal_synchronizer')->syncAll();
27
28
            return $this->findTerminalByTitle($title, false);
29
        }
30
31
        return $terminal;
32
    }
33
34
    /**
35
     * @param string $slug
36
     * @param bool   $fetch
37
     *
38
     * @return Terminal|null
39
     */
40
    public function findTerminalBySlug(string $slug, $fetch = false): ?Terminal
41
    {
42
        /** @var Terminal $terminal */
43
        $terminal = $this->findOneBy([
44
            'slug' => $slug,
45
        ]);
46
47
        if ($fetch) {
48
            $this->container->get('loevgaard_dandomain_altapay.terminal_synchronizer')->syncAll();
49
50
            return $this->findTerminalBySlug($slug, false);
51
        }
52
53
        return $terminal;
54
    }
55
}
56