JWSVerifier   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A verifyWithKeySet() 0 21 2
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\Bundle\JoseFramework\Services;
15
16
use Jose\Bundle\JoseFramework\Event\JWSVerificationFailureEvent;
17
use Jose\Bundle\JoseFramework\Event\JWSVerificationSuccessEvent;
18
use Jose\Component\Core\AlgorithmManager;
19
use Jose\Component\Core\JWK;
20
use Jose\Component\Core\JWKSet;
21
use Jose\Component\Signature\JWS;
22
use Jose\Component\Signature\JWSVerifier as BaseJWSVerifier;
23
use Psr\EventDispatcher\EventDispatcherInterface;
24
25
final class JWSVerifier extends BaseJWSVerifier
26
{
27
    /**
28
     * @var EventDispatcherInterface
29
     */
30
    private $eventDispatcher;
31
32
    public function __construct(AlgorithmManager $signatureAlgorithmManager, EventDispatcherInterface $eventDispatcher)
33
    {
34
        parent::__construct($signatureAlgorithmManager);
35
        $this->eventDispatcher = $eventDispatcher;
36
    }
37
38
    public function verifyWithKeySet(JWS $jws, JWKSet $jwkset, int $signatureIndex, ?string $detachedPayload = null, JWK &$jwk = null): bool
39
    {
40
        $success = parent::verifyWithKeySet($jws, $jwkset, $signatureIndex, $detachedPayload, $jwk);
41
        if ($success) {
42
            $this->eventDispatcher->dispatch(new JWSVerificationSuccessEvent(
0 ignored issues
show
Documentation introduced by Spomky
new \Jose\Bundle\JoseFra...$detachedPayload, $jwk) is of type object<Jose\Bundle\JoseF...rificationSuccessEvent>, but the function expects a object<Psr\EventDispatcher\object>.

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...
43
                $jws,
44
                $jwkset,
45
                $signatureIndex,
46
                $detachedPayload,
47
                $jwk
0 ignored issues
show
Bug introduced by Spomky
It seems like $jwk defined by parameter $jwk on line 38 can be null; however, Jose\Bundle\JoseFramewor...essEvent::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
48
            ));
49
        } else {
50
            $this->eventDispatcher->dispatch(new JWSVerificationFailureEvent(
0 ignored issues
show
Documentation introduced by Spomky
new \Jose\Bundle\JoseFra...kset, $detachedPayload) is of type object<Jose\Bundle\JoseF...rificationFailureEvent>, but the function expects a object<Psr\EventDispatcher\object>.

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...
51
                $jws,
52
                $jwkset,
53
                $detachedPayload
54
            ));
55
        }
56
57
        return $success;
58
    }
59
}
60