StringToObjectConverter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Ddeboer\DataImport\ValueConverter;
4
5
use Doctrine\Common\Persistence\ObjectRepository;
6
7
/**
8
 * Converts a string to an object
9
 *
10
 * @author Markus Bachmann <[email protected]>
11
 */
12
class StringToObjectConverter
13
{
14
    /**
15
     * @var ObjectRepository
16
     */
17
    private $repository;
18
19
    /**
20
     * @var string
21
     */
22
    private $property;
23
24
    /**
25
     * @param ObjectRepository $repository
26
     * @param string           $property
27
     */
28 1
    public function __construct(ObjectRepository $repository, $property)
29
    {
30 1
        $this->repository = $repository;
31 1
        $this->property = $property;
32 1
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1
    public function __invoke($input)
38
    {
39 1
        $method = 'findOneBy'.ucfirst($this->property);
40
41 1
        return $this->repository->$method($input);
42
    }
43
}
44