JWSSerializerManagerFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 12 3
A names() 0 4 1
A all() 0 4 1
A add() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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
use InvalidArgumentException;
17
18
class JWSSerializerManagerFactory
19
{
20
    /**
21
     * @var JWSSerializer[]
22
     */
23
    private $serializers = [];
24
25
    /**
26
     * @param string[] $names
27
     *
28
     * @throws InvalidArgumentException if the serializer is not supported
29
     */
30
    public function create(array $names): JWSSerializerManager
31
    {
32
        $serializers = [];
33
        foreach ($names as $name) {
34
            if (!isset($this->serializers[$name])) {
35
                throw new InvalidArgumentException(sprintf('Unsupported serializer "%s".', $name));
36
            }
37
            $serializers[] = $this->serializers[$name];
38
        }
39
40
        return new JWSSerializerManager($serializers);
41
    }
42
43
    /**
44
     * @return string[]
45
     */
46
    public function names(): array
47
    {
48
        return array_keys($this->serializers);
49
    }
50
51
    /**
52
     * @return JWSSerializer[]
53
     */
54
    public function all(): array
55
    {
56
        return $this->serializers;
57
    }
58
59
    public function add(JWSSerializer $serializer): void
60
    {
61
        $this->serializers[$serializer->name()] = $serializer;
62
    }
63
}
64