Passed
Pull Request — master (#21)
by Pavel
06:33
created

JmsDoctrineHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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\EntityToIdNormalizer;
9
10
final class JmsDoctrineHandler
11
{
12
    const TYPE = 'DoctrineAssociation';
13
14
    /** @var  ManagerRegistry */
15
    private $registry;
16
    /** @var  EntityToIdNormalizer */
17
    private $converter;
18
19
    /**
20
     * JmsDoctrineHandler constructor.
21
     *
22
     * @param ManagerRegistry $registry
23
     */
24
    public function __construct(ManagerRegistry $registry)
25
    {
26
        $this->registry  = $registry;
27
        $this->converter = new EntityToIdNormalizer($this->registry);
28
    }
29
30
    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
    {
32
        if ($relation instanceof \Traversable) {
33
            $relation = iterator_to_array($relation);
34
        }
35
36
        if (is_array($relation)) {
37
            return array_map([$this->converter, 'normalize'], $relation);
38
        }
39
40
        return $this->converter->normalize($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
        // obtain params from deeps
46
        // $class = $type['params'][0]['name'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        // return $this->converter->denormalize($data, $class);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
49
        // fixme
50
        throw new \BadMethodCallException('Not supported at the moment');
51
    }
52
}
53