GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CompositeSerializer::serialize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Serialize\ObjectSerializer;
7
8
9
use Gica\Serialize\ObjectSerializer\Exception\ValueNotSerializable;
10
11
class CompositeSerializer implements Serializer
12
{
13
    /**
14
     * @var Serializer[]
15
     */
16
    private $serializers;
17
18
    /**
19
     * @param Serializer[] $serializers
20
     */
21 8
    public function __construct(
22
        array $serializers
23
    )
24
    {
25 8
        $this->serializers = $serializers;
26 8
    }
27
28 7
    public function serialize($value)
29
    {
30 7
        foreach ($this->serializers as $serializer) {
31
            try {
32 2
                return $serializer->serialize($value);
33 1
            } catch (ValueNotSerializable $exception) {
34 1
                continue;
35
            }
36
        }
37
38 5
        throw new ValueNotSerializable("None of the serializers worked");
39
    }
40
}