Completed
Push — master ( cd41f7...e61615 )
by Pavel
07:44 queued 02:46
created

JmsDoctrineHandler::convertEntityToIds()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 3
eloc 7
nc 2
nop 1
crap 3.0261
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Adaptors\JmsSerializer;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use JMS\Serializer\Context;
7
use JMS\Serializer\VisitorInterface;
8
use ScayTrase\Api\Cruds\Adaptors\DoctrineOrm\EntityToIdConverter;
9
10
final class JmsDoctrineHandler
11
{
12
    const TYPE = 'DoctrineAssociation';
13
14
    /** @var  ManagerRegistry */
15
    private $registry;
16
    /** @var  EntityToIdConverter */
17
    private $converter;
18
19
    /**
20
     * JmsDoctrineHandler constructor.
21
     *
22 5
     * @param ManagerRegistry $registry
23
     */
24 5
    public function __construct(ManagerRegistry $registry)
25 5
    {
26
        $this->registry  = $registry;
27 5
        $this->converter = new EntityToIdConverter($this->registry);
28
    }
29 5
30 5
    public function serializeRelation(VisitorInterface $visitor, $relation, array $type, Context $context)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor 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...
Unused Code introduced by
The parameter $type 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...
Unused Code introduced by
The parameter $context 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...
31 5
    {
32
        if ($relation instanceof \Traversable) {
33 5
            $relation = iterator_to_array($relation);
34 5
        }
35
36
        if (is_array($relation)) {
37 3
            return array_map([$this, 'convertEntityToIds'], $relation);
38
        }
39
40
        return $this->converter->convert($relation);
41
    }
42
43
    public function deserializeRelation(VisitorInterface $visitor, $data, array $type, Context $context)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor 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...
Unused Code introduced by
The parameter $data 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...
Unused Code introduced by
The parameter $type 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...
Unused Code introduced by
The parameter $context 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...
44
    {
45
        // fixme
46 3
        throw new \BadMethodCallException('Not supported at the moment');
47
    }
48
}
49