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.
Completed
Push — master ( 7c537a...4aef39 )
by Ítalo
02:24
created

OperatorConditionSerializer::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2016, HelloFresh GmbH.
4
 * All rights reserved.
5
 *
6
 * This source code is licensed under the MIT license found in the
7
 * LICENSE file in the root directory of this source tree.
8
 */
9
10
namespace HelloFresh\FeatureToggle\Serializer;
11
12
use Collections\MapInterface;
13
use HelloFresh\FeatureToggle\OperatorCondition;
14
15
/**
16
 * Hand written serializer to serialize an OperatorCondition to a php array.
17
 */
18
class OperatorConditionSerializer
19
{
20
    private $operatorSerializer;
21
22
    /**
23
     * @param OperatorSerializer $operatorSerializer
24
     */
25 8
    public function __construct(OperatorSerializer $operatorSerializer)
26
    {
27 8
        $this->operatorSerializer = $operatorSerializer;
28 8
    }
29
30
    /**
31
     * @param OperatorCondition $condition
32
     *
33
     * @return string
34
     */
35 2
    public function serialize(OperatorCondition $condition)
36
    {
37
        return array(
38 1
            'name' => 'operator-condition',
39 1
            'key' => $condition->getKey(),
40 2
            'operator' => $this->operatorSerializer->serialize($condition->getOperator()),
41 1
        );
42
    }
43
44
    /**
45
     * @param MapInterface $condition
46
     *
47
     * @return OperatorCondition
48
     */
49 7
    public function deserialize(MapInterface $condition)
50
    {
51 7
        $name = $condition->get('name');
52
53 3
        if ($name !== 'operator-condition') {
54 1
            throw new \RuntimeException(sprintf('Unable to deserialize operator with name "%s".', $name));
55
        }
56 2
        $operator = $this->operatorSerializer->deserialize($condition->get('operator'));
57
58 2
        return new OperatorCondition($condition->get('key'), $operator);
59
    }
60
}
61