| Total Complexity | 9 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class EntityGuesser extends AbstractGuesser implements GuesserInterface |
||
| 8 | { |
||
| 9 | public function __construct(Bag $bag) |
||
| 10 | { |
||
| 11 | $this->bag = $bag; |
||
|
|
|||
| 12 | } |
||
| 13 | |||
| 14 | public function supports(array $mapping) |
||
| 15 | { |
||
| 16 | if (array_key_exists('targetEntity', $mapping)) { |
||
| 17 | |||
| 18 | return $this->bag->getCollection($mapping['targetEntity'])->count() > 0; |
||
| 19 | } |
||
| 20 | |||
| 21 | return false; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function transform($str, array $mapping) |
||
| 25 | { |
||
| 26 | $str = strlen((string) $str) ? $str : null; |
||
| 27 | |||
| 28 | if (null !== $record = $this->bag->getCollection($mapping['targetEntity'])->search($str)) { |
||
| 29 | |||
| 30 | return $record->getEntity(); |
||
| 31 | } |
||
| 32 | |||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function fake(array $mapping) |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getName() |
||
| 50 | { |
||
| 54 |