Completed
Push — master ( 677329...636a3e )
by Joachim
14:34
created

TerminalManager::getClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
namespace Loevgaard\DandomainAltapayBundle\Manager;
3
4
use Doctrine\Common\Persistence\ObjectManager;
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Loevgaard\DandomainAltapayBundle\Entity\TerminalInterface;
7
8
class TerminalManager
9
{
10
    /**
11
     * @var ObjectManager
12
     */
13
    protected $objectManager;
14
15
    /**
16
     * @var string
17
     */
18
    protected $class;
19
20
    public function __construct(ObjectManager $objectManager, string $class)
0 ignored issues
show
Unused Code introduced by
The parameter $objectManager is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        $this->class = $class;
23
    }
24
25
    /**
26
     * @return ObjectRepository
27
     */
28
    protected function getRepository()
29
    {
30
        return $this->objectManager->getRepository($this->getClass());
31
    }
32
33
    public function getClass() : string
34
    {
35
        if (false !== strpos($this->class, ':')) {
36
            $metadata = $this->objectManager->getClassMetadata($this->class);
37
            $this->class = $metadata->getName();
38
        }
39
        return $this->class;
40
    }
41
42
    /**
43
     * @param string $slug
44
     * @return TerminalInterface|null
45
     */
46
    public function findTerminalBySlug(string $slug) : ?TerminalInterface
47
    {
48
        /** @var TerminalInterface $terminal */
49
        $terminal = $this->getRepository()->findOneBy([
50
            'slug' => $slug
51
        ]);
52
53
        return $terminal;
54
    }
55
}