Completed
Push — master ( 022625...2b82d4 )
by Florent
05:58
created

CommonCipheringMethods   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
c 2
b 0
f 0
lcom 3
cbo 3
dl 0
loc 95
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedKeyEncryptionAlgorithms() 0 4 1
A setKeyEncryptionAlgorithms() 0 14 4
A getSupportedContentEncryptionAlgorithms() 0 4 1
A setContentEncryptionAlgorithms() 0 14 4
A getSupportedCompressionMethods() 0 4 1
A setCompressionMethods() 0 14 4
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Behaviour;
13
14
use Jose\Algorithm\ContentEncryptionAlgorithmInterface;
15
use Jose\Algorithm\KeyEncryptionAlgorithmInterface;
16
use Jose\Compression\CompressionInterface;
17
18
trait CommonCipheringMethods
19
{
20
    /**
21
     * @var string[]
22
     */
23
    private $key_encryption_algorithms;
24
25
    /**
26
     * @var string[]
27
     */
28
    private $content_encryption_algorithms;
29
30
    /**
31
     * @var string[]
32
     */
33
    private $compression_methods;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getSupportedKeyEncryptionAlgorithms()
39
    {
40
        return $this->key_encryption_algorithms;
41
    }
42
43
    /**
44
     * @param string[]|\Jose\Algorithm\KeyEncryptionAlgorithmInterface[] $key_encryption_algorithms
45
     */
46
    private function setKeyEncryptionAlgorithms($key_encryption_algorithms)
47
    {
48
        $result = [];
49
        foreach ($key_encryption_algorithms as $key_encryption_algorithm) {
50
            if (is_string($key_encryption_algorithm)) {
51
                $result[] = $key_encryption_algorithm;
52
            } elseif ($key_encryption_algorithm instanceof KeyEncryptionAlgorithmInterface) {
53
                $result[] = $key_encryption_algorithm->getAlgorithmName();
54
            } else {
55
                throw new \InvalidArgumentException('Parameter must be a string or an instance of KeyEncryptionAlgorithmInterface');
56
            }
57
        }
58
        $this->key_encryption_algorithms = $result;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getSupportedContentEncryptionAlgorithms()
65
    {
66
        return $this->content_encryption_algorithms;
67
    }
68
69
    /**
70
     * @param string[]|\Jose\Algorithm\ContentEncryptionAlgorithmInterface[] $content_encryption_algorithms
71
     */
72
    private function setContentEncryptionAlgorithms($content_encryption_algorithms)
73
    {
74
        $result = [];
75
        foreach ($content_encryption_algorithms as $content_encryption_algorithm) {
76
            if (is_string($content_encryption_algorithm)) {
77
                $result[] = $content_encryption_algorithm;
78
            } elseif ($content_encryption_algorithm instanceof ContentEncryptionAlgorithmInterface) {
79
                $result[] = $content_encryption_algorithm->getAlgorithmName();
80
            } else {
81
                throw new \InvalidArgumentException('Parameter must be a string or an instance of KeyEncryptionAlgorithmInterface');
82
            }
83
        }
84
        $this->content_encryption_algorithms = $result;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getSupportedCompressionMethods()
91
    {
92
        return $this->compression_methods;
93
    }
94
95
    /**
96
     * @param string[]|\Jose\Compression\CompressionInterface[] $compression_methods
97
     */
98
    private function setCompressionMethods($compression_methods)
99
    {
100
        $result = [];
101
        foreach ($compression_methods as $compression_method) {
102
            if (is_string($compression_method)) {
103
                $result[] = $compression_method;
104
            } elseif ($compression_method instanceof CompressionInterface) {
105
                $result[] = $compression_method->getMethodName();
106
            } else {
107
                throw new \InvalidArgumentException('Parameter must be a string or an instance of CompressionInterface');
108
            }
109
        }
110
        $this->compression_methods = $result;
111
    }
112
}
113