Failed Conditions
Push — v7 ( 514019...c6ee27 )
by Florent
02:57
created

JWSSerializerManagerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 12 3
A add() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Signature\Serializer;
15
16
/**
17
 * Class JWSSerializerManagerFactory.
18
 */
19
final class JWSSerializerManagerFactory
20
{
21
    /**
22
     * @var JWSSerializerInterface[]
23
     */
24
    private $serializers = [];
25
26
    /**
27
     * @param string[] $names
28
     *
29
     * @return JWSSerializerManager
30
     */
31
    public function create(array $names): JWSSerializerManager
32
    {
33
        $serializers = [];
34
        foreach ($names as $name) {
35
            if (!array_key_exists($name, $this->serializers)) {
36
                throw new \InvalidArgumentException(sprintf('Unsupported serialier "%s".', $name));
37
            }
38
            $serializers[] = $this->serializers[$name];
39
        }
40
41
        return JWSSerializerManager::create($serializers);
42
    }
43
44
    /**
45
     * @param JWSSerializerInterface $serializer
46
     *
47
     * @return JWSSerializerManagerFactory
48
     */
49
    public function add(JWSSerializerInterface $serializer): JWSSerializerManagerFactory
50
    {
51
        $this->serializers[$serializer->name()] = $serializer;
52
53
        return $this;
54
    }
55
}
56