Completed
Push — develop ( 4c84f9...64a224 )
by Florent
05:18
created

ServiceFactory::createDecrypter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
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 SpomkyLabs\JoseBundle\Service;
13
14
use Jose\Factory\DecrypterFactory;
15
use Jose\Factory\EncrypterFactory;
16
use Jose\Factory\SignerFactory;
17
use Jose\Factory\VerifierFactory;
18
use Psr\Log\LoggerInterface;
19
20
final class ServiceFactory
21
{
22
    /**
23
     * @var \SpomkyLabs\JoseBundle\Service\AlgorithmManager
24
     */
25
    private $algorithm_manager;
26
27
    /**
28
     * @var \SpomkyLabs\JoseBundle\Service\CompressionManager
29
     */
30
    private $compression_manager;
31
32
    /**
33
     * ServiceFactory constructor.
34
     *
35
     * @param \SpomkyLabs\JoseBundle\Service\AlgorithmManager   $algorithm_manager
36
     * @param \SpomkyLabs\JoseBundle\Service\CompressionManager $compression_manager
37
     */
38
    public function __construct(AlgorithmManager $algorithm_manager, CompressionManager $compression_manager)
39
    {
40
        $this->algorithm_manager = $algorithm_manager;
41
        $this->compression_manager = $compression_manager;
42
    }
43
44
    /**
45
     * @param string[]                      $selected_algorithms
46
     * @param string[]                      $selected_compression_methods
47
     * @param \Psr\Log\LoggerInterface|null $logger
48
     *
49
     * @return \Jose\EncrypterInterface
50
     */
51 View Code Duplication
    public function createEncrypter(array $selected_algorithms, array $selected_compression_methods, LoggerInterface $logger = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
54
        $compression_methods = $this->compression_manager->getSelectedCompressionMethods($selected_compression_methods);
55
56
        return EncrypterFactory::createEncrypter($algorithms, $compression_methods, $logger);
0 ignored issues
show
Documentation introduced by
$algorithms is of type array<integer,object<Jos...lgorithm\JWAInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$compression_methods is of type array<integer,object<Jos...\CompressionInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
    }
58
59
    /**
60
     * @param string[]                      $selected_algorithms
61
     * @param string[]                      $selected_compression_methods
62
     * @param \Psr\Log\LoggerInterface|null $logger
63
     *
64
     * @return \Jose\DecrypterInterface
65
     */
66 View Code Duplication
    public function createDecrypter(array $selected_algorithms, array $selected_compression_methods, LoggerInterface $logger = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
69
        $compression_methods = $this->compression_manager->getSelectedCompressionMethods($selected_compression_methods);
70
71
        return DecrypterFactory::createDecrypter($algorithms, $compression_methods, $logger);
0 ignored issues
show
Documentation introduced by
$algorithms is of type array<integer,object<Jos...lgorithm\JWAInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$compression_methods is of type array<integer,object<Jos...\CompressionInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
    }
73
74
    /**
75
     * @param string[]                      $selected_algorithms
76
     * @param \Psr\Log\LoggerInterface|null $logger
77
     *
78
     * @return \Jose\SignerInterface
79
     */
80
    public function createSigner(array $selected_algorithms, LoggerInterface $logger = null)
81
    {
82
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
83
84
        return SignerFactory::createSigner($algorithms, $logger);
0 ignored issues
show
Documentation introduced by
$algorithms is of type array<integer,object<Jos...lgorithm\JWAInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
    }
86
87
    /**
88
     * @param string[]                      $selected_algorithms
89
     * @param \Psr\Log\LoggerInterface|null $logger
90
     *
91
     * @return \Jose\VerifierInterface
92
     */
93
    public function createVerifier(array $selected_algorithms, LoggerInterface $logger = null)
94
    {
95
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
96
        
97
        return VerifierFactory::createVerifier($algorithms, $logger);
0 ignored issues
show
Documentation introduced by
$algorithms is of type array<integer,object<Jos...lgorithm\JWAInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
98
    }
99
}
100