Completed
Push — master ( 677e94...463d73 )
by Gerrit
02:18
created

EntityArgument::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\SymfonyGenerics\Arguments;
14
15
use Addiks\SymfonyGenerics\Arguments\ArgumentInterface;
16
use Doctrine\Common\Persistence\ObjectManager;
17
18
final class EntityArgument implements ArgumentInterface
19
{
20
21
    /**
22
     * @var string
23
     */
24
    private $entityClass;
25
26
    /**
27
     * @var ArgumentInterface
28
     */
29
    private $id;
30
31
    /**
32
     * @var ObjectManager
33
     */
34
    private $objectManager;
35
36
    public function __construct(
37
        ObjectManager $objectManager,
38
        string $entityClass,
39
        ArgumentInterface $id
40
    ) {
41
        $this->entityClass = $entityClass;
42
        $this->id = $id;
43
        $this->objectManager = $objectManager;
44
    }
45
46
    public function getValue()
47
    {
48
        return $this->objectManager->find(
49
            $this->entityClass,
50
            $this->id->getValue()
51
        );
52
    }
53
54
}
55