JWSBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\JWSBuiltFailureEvent;
17
use Jose\Bundle\JoseFramework\Event\JWSBuiltSuccessEvent;
18
use Jose\Component\Core\AlgorithmManager;
19
use Jose\Component\Signature\JWS;
20
use Jose\Component\Signature\JWSBuilder as BaseJWSBuilder;
21
use Psr\EventDispatcher\EventDispatcherInterface;
22
use Throwable;
23
24
final class JWSBuilder extends BaseJWSBuilder
25
{
26
    /**
27
     * @var EventDispatcherInterface
28
     */
29
    private $eventDispatcher;
30
31
    public function __construct(AlgorithmManager $signatureAlgorithmManager, EventDispatcherInterface $eventDispatcher)
32
    {
33
        parent::__construct($signatureAlgorithmManager);
34
        $this->eventDispatcher = $eventDispatcher;
35
    }
36
37
    public function build(): JWS
38
    {
39
        try {
40
            $jws = parent::build();
41
            $this->eventDispatcher->dispatch(new JWSBuiltSuccessEvent($jws));
0 ignored issues
show
Documentation introduced by
new \Jose\Bundle\JoseFra...BuiltSuccessEvent($jws) is of type object<Jose\Bundle\JoseF...t\JWSBuiltSuccessEvent>, 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...
42
43
            return $jws;
44
        } catch (Throwable $throwable) {
45
            $this->eventDispatcher->dispatch(new JWSBuiltFailureEvent(
0 ignored issues
show
Documentation introduced by
new \Jose\Bundle\JoseFra...oadEncoded, $throwable) is of type object<Jose\Bundle\JoseF...t\JWSBuiltFailureEvent>, 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...
46
                $this->payload,
47
                $this->signatures,
48
                $this->isPayloadDetached,
49
                $this->isPayloadEncoded,
50
                $throwable
51
            ));
52
53
            throw $throwable;
54
        }
55
    }
56
}
57