Completed
Push — develop ( 64a224...17d645 )
by Florent
03:11
created

ServiceFactory::createChecker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
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\CheckerManagerFactory;
15
use Jose\Factory\DecrypterFactory;
16
use Jose\Factory\EncrypterFactory;
17
use Jose\Factory\SignerFactory;
18
use Jose\Factory\VerifierFactory;
19
use Psr\Log\LoggerInterface;
20
21
final class ServiceFactory
22
{
23
    /**
24
     * @var \SpomkyLabs\JoseBundle\Service\AlgorithmManager
25
     */
26
    private $algorithm_manager;
27
28
    /**
29
     * @var \SpomkyLabs\JoseBundle\Service\CompressionManager
30
     */
31
    private $compression_manager;
32
33
    /**
34
     * @var \SpomkyLabs\JoseBundle\Service\CheckerManager
35
     */
36
    private $checker_manager;
37
38
    /**
39
     * ServiceFactory constructor.
40
     *
41
     * @param \SpomkyLabs\JoseBundle\Service\AlgorithmManager   $algorithm_manager
42
     * @param \SpomkyLabs\JoseBundle\Service\CompressionManager $compression_manager
43
     * @param \SpomkyLabs\JoseBundle\Service\CheckerManager     $checker_manager
44
     */
45
    public function __construct(AlgorithmManager $algorithm_manager, CompressionManager $compression_manager, CheckerManager $checker_manager)
46
    {
47
        $this->algorithm_manager = $algorithm_manager;
48
        $this->compression_manager = $compression_manager;
49
        $this->checker_manager = $checker_manager;
50
    }
51
52
    /**
53
     * @param string[]                      $selected_algorithms
54
     * @param string[]                      $selected_compression_methods
55
     * @param \Psr\Log\LoggerInterface|null $logger
56
     *
57
     * @return \Jose\EncrypterInterface
58
     */
59 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...
60
    {
61
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
62
        $compression_methods = $this->compression_manager->getSelectedCompressionMethods($selected_compression_methods);
63
64
        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...
65
    }
66
67
    /**
68
     * @param string[]                      $selected_algorithms
69
     * @param string[]                      $selected_compression_methods
70
     * @param \Psr\Log\LoggerInterface|null $logger
71
     *
72
     * @return \Jose\DecrypterInterface
73
     */
74 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...
75
    {
76
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
77
        $compression_methods = $this->compression_manager->getSelectedCompressionMethods($selected_compression_methods);
78
79
        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...
80
    }
81
82
    /**
83
     * @param string[]                      $selected_algorithms
84
     * @param \Psr\Log\LoggerInterface|null $logger
85
     *
86
     * @return \Jose\SignerInterface
87
     */
88
    public function createSigner(array $selected_algorithms, LoggerInterface $logger = null)
89
    {
90
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
91
92
        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...
93
    }
94
95
    /**
96
     * @param string[]                      $selected_algorithms
97
     * @param \Psr\Log\LoggerInterface|null $logger
98
     *
99
     * @return \Jose\VerifierInterface
100
     */
101
    public function createVerifier(array $selected_algorithms, LoggerInterface $logger = null)
102
    {
103
        $algorithms = $this->algorithm_manager->getSelectedAlgorithmMethods($selected_algorithms);
104
        
105
        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...
106
    }
107
108
    /**
109
     * @param string[]                      $selected_claim_checkers
110
     * @param string[]                      $selected_header_checkers
111
     * @param \Psr\Log\LoggerInterface|null $logger
112
     *
113
     * @return \Jose\Checker\CheckerManagerInterface
114
     */
115
    public function createChecker(array $selected_claim_checkers, array $selected_header_checkers, LoggerInterface $logger = null)
0 ignored issues
show
Unused Code introduced by
The parameter $logger is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
    {
117
        $claim_checkers = $this->checker_manager->getSelectedClaimChecker($selected_claim_checkers);
118
        $header_checkers = $this->checker_manager->getSelectedHeaderChecker($selected_header_checkers);
119
        
120
        return CheckerManagerFactory::createClaimCheckerManager($claim_checkers, $header_checkers);
0 ignored issues
show
Documentation introduced by
$claim_checkers is of type array<integer,object<Jos...ClaimCheckerInterface>>, 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
$header_checkers is of type array<integer,object<Jos...eaderCheckerInterface>>, 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...
121
    }
122
}
123