GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AllParametersShaComposer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A compose() 0 16 3
A addParameterFilter() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Marlon Ogone package.
5
 *
6
 * (c) Marlon BVBA <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ogone\ShaComposer;
13
14
use Ogone\ParameterFilter\GeneralParameterFilter;
15
use Ogone\Passphrase;
16
use Ogone\HashAlgorithm;
17
use Ogone\ParameterFilter\ParameterFilter;
18
19
/**
20
 * SHA string composition the "new way", using all parameters in the ogone response
21
 */
22
class AllParametersShaComposer implements ShaComposer
23
{
24
    /** @var array of ParameterFilter */
25
    private $parameterFilters;
26
27
    /**
28
     * @var string Passphrase
29
     */
30
    private $passphrase;
31
32
    /**
33
     * @var HashAlgorithm
34
     */
35
    private $hashAlgorithm;
36
37 6
    public function __construct(Passphrase $passphrase, HashAlgorithm $hashAlgorithm = null)
38
    {
39 6
        $this->passphrase = $passphrase;
0 ignored issues
show
Documentation Bug introduced by
It seems like $passphrase of type object<Ogone\Passphrase> is incompatible with the declared type string of property $passphrase.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
41 6
        $this->addParameterFilter(new GeneralParameterFilter);
42
43 6
        $this->hashAlgorithm = $hashAlgorithm ?: new HashAlgorithm(HashAlgorithm::HASH_SHA1);
44 6
    }
45
46 6
    public function compose(array $parameters)
47
    {
48 6
        foreach ($this->parameterFilters as $parameterFilter) {
49 6
            $parameters = $parameterFilter->filter($parameters);
50
        }
51
52 6
        ksort($parameters);
53
54
        // compose SHA string
55 6
        $shaString = '';
56 6
        foreach ($parameters as $key => $value) {
57 6
            $shaString .= $key . '=' . $value . $this->passphrase;
58
        }
59
60 6
        return strtoupper(hash($this->hashAlgorithm, $shaString));
61
    }
62
63 6
    public function addParameterFilter(ParameterFilter $parameterFilter)
64
    {
65 6
        $this->parameterFilters[] = $parameterFilter;
66 6
    }
67
}
68