Passed
Push — master ( 40ff2a...9a8bc4 )
by Dominik
02:05
created

ObjectSerializer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serializeField() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Serializer\Field;
6
7
use Chubbyphp\Serialization\Accessor\AccessorInterface;
8
use Chubbyphp\Serialization\SerializerInterface;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
11
final class ObjectSerializer implements FieldSerializerInterface
12
{
13
    /**
14
     * @var AccessorInterface
15
     */
16
    private $accessor;
17
18
    /**
19
     * @param AccessorInterface $accessor
20
     */
21
    public function __construct(AccessorInterface $accessor)
22
    {
23
        $this->accessor = $accessor;
24
    }
25
26
    /**
27
     * @param string                   $path
28
     * @param Request                  $request
29
     * @param object                   $object
30
     * @param SerializerInterface|null $serializer
31
     *
32
     * @return mixed
33
     */
34
    public function serializeField(string $path, Request $request, $object, SerializerInterface $serializer = null)
35
    {
36
        return $serializer->serialize($request, $this->accessor->getValue($object), $path);
0 ignored issues
show
Bug introduced by
It seems like $serializer is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
37
    }
38
}
39