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

ObjectSerializer::serializeField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
crap 2
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