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

TerminalRepository::findTerminalByTitle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 7
nc 2
nop 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