Completed
Push — master ( 463d73...47ba96 )
by Gerrit
02:04
created

EntityArgument   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 40
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A resolve() 0 10 1
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\Argument;
16
use Doctrine\Common\Persistence\ObjectManager;
17
18
final class EntityArgument implements Argument
19
{
20
21
    /**
22
     * @var string
23
     */
24
    private $entityClass;
25
26
    /**
27
     * @var Argument
28
     */
29
    private $id;
30
31
    /**
32
     * @var ObjectManager
33
     */
34
    private $objectManager;
35
36 1
    public function __construct(
37
        ObjectManager $objectManager,
38
        string $entityClass,
39
        Argument $id
40
    ) {
41 1
        $this->entityClass = $entityClass;
42 1
        $this->id = $id;
43 1
        $this->objectManager = $objectManager;
44 1
    }
45
46 1
    public function resolve()
47
    {
48
        /** @var string $entityId */
49 1
        $entityId = $this->id->resolve();
50
51 1
        return $this->objectManager->find(
52 1
            $this->entityClass,
53 1
            $entityId
54
        );
55
    }
56
57
}
58