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   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A serialize() 0 12 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
}