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.

OperatorSerializer   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 91.11%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 18
c 1
b 0
f 1
lcom 0
cbo 9
dl 0
loc 64
ccs 41
cts 45
cp 0.9111
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
D serialize() 0 27 9
C deserialize() 0 23 9
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\Operator\EqualsTo;
14
use HelloFresh\FeatureToggle\Operator\GreaterThan;
15
use HelloFresh\FeatureToggle\Operator\GreaterThanEqual;
16
use HelloFresh\FeatureToggle\Operator\InSet;
17
use HelloFresh\FeatureToggle\Operator\LessThan;
18
use HelloFresh\FeatureToggle\Operator\LessThanEqual;
19
use HelloFresh\FeatureToggle\Operator\MatchesRegex;
20
use HelloFresh\FeatureToggle\Operator\OperatorInterface;
21
use HelloFresh\FeatureToggle\Operator\Percentage;
22
23
/**
24
 * Hand written serializer to serialize an Operator to a php array.
25
 */
26
class OperatorSerializer
27
{
28
    /**
29
     * @param OperatorInterface $operator
30
     *
31
     * @return string
32
     */
33 8
    public function serialize(OperatorInterface $operator)
34
    {
35 8
        switch (true) {
36 8
            case $operator instanceof EqualsTo:
37
                return ['name' => 'equals-to', 'value' => $operator->getValue()];
38 8
            case $operator instanceof GreaterThan:
39 2
                return ['name' => 'greater-than', 'value' => $operator->getValue()];
40 6
            case $operator instanceof GreaterThanEqual:
41 1
                return ['name' => 'greater-than-equal', 'value' => $operator->getValue()];
42 5
            case $operator instanceof InSet:
43 1
                return ['name' => 'in-set', 'values' => $operator->getValues()];
44 4
            case $operator instanceof LessThan:
45 1
                return ['name' => 'less-than', 'value' => $operator->getValue()];
46 3
            case $operator instanceof LessThanEqual:
47 1
                return ['name' => 'less-than-equal', 'value' => $operator->getValue()];
48 2
            case $operator instanceof Percentage:
49
                return [
50 1
                    'name' => 'percentage',
51 1
                    'percentage' => $operator->getPercentage(),
52 1
                    'shift' => $operator->getShift()
53 1
                ];
54 1
            case $operator instanceof MatchesRegex:
55
                return ['name' => 'matches-regex', 'value' => $operator->getValue()];
56 1
            default:
57 1
                throw new \RuntimeException(sprintf('Unknown operator %s.', get_class($operator)));
58 1
        }
59
    }
60
61
    /**
62
     * @param MapInterface $operator
63
     *
64
     * @return OperatorInterface
65
     */
66 18
    public function deserialize(MapInterface $operator)
67
    {
68 18
        switch ($operator->get('name')) {
69 17
            case 'equals-to':
70
                return new EqualsTo($operator->get('value'));
71 17
            case 'greater-than':
72 4
                return new GreaterThan($operator->get('value'));
73 13
            case 'greater-than-equal':
74 2
                return new GreaterThanEqual($operator->get('value'));
75 11
            case 'in-set':
76 2
                return new InSet($operator->get('values'));
77 9
            case 'less-than':
78 2
                return new LessThan($operator->get('value'));
79 7
            case 'less-than-equal':
80 2
                return new LessThanEqual($operator->get('value'));
81 5
            case 'percentage':
82 4
                return new Percentage($operator->get('percentage'), $operator->get('shift'));
83 1
            case 'matches-regex':
84
                return new MatchesRegex($operator->get('value'));
85 1
            default:
86 1
                throw new \RuntimeException(sprintf('Unknown operator with name "%s".', $operator->get('name')));
87 1
        }
88
    }
89
}
90