Completed
Push — master ( 7b61ef...71e756 )
by Florent
08:30 queued 07:08
created

NestedTokenBuilder::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\NestedTokenIssuedEvent;
17
use Jose\Component\Encryption\JWEBuilder;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Jose\Bundle\JoseFramework\Services\JWEBuilder.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
use Jose\Component\Encryption\Serializer\JWESerializerManager;
19
use Jose\Component\NestedToken\NestedTokenBuilder as BaseNestedTokenBuilder;
20
use Jose\Component\Signature\JWSBuilder;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Jose\Bundle\JoseFramework\Services\JWSBuilder.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
use Jose\Component\Signature\Serializer\JWSSerializerManager;
22
use Psr\EventDispatcher\EventDispatcherInterface;
23
24
final class NestedTokenBuilder extends BaseNestedTokenBuilder
25
{
26
    /**
27
     * @var EventDispatcherInterface
28
     */
29
    private $eventDispatcher;
30
31
    public function __construct(JWEBuilder $jweBuilder, JWESerializerManager $jweSerializerManager, JWSBuilder $jwsBuilder, JWSSerializerManager $jwsSerializerManager, EventDispatcherInterface $eventDispatcher)
32
    {
33
        parent::__construct($jweBuilder, $jweSerializerManager, $jwsBuilder, $jwsSerializerManager);
34
        $this->eventDispatcher = $eventDispatcher;
35
    }
36
37
    public function create(string $payload, array $signatures, string $jws_serialization_mode, array $jweSharedProtectedHeader, array $jweSharedHeader, array $recipients, string $jwe_serialization_mode, ?string $aad = null): string
38
    {
39
        $nestedToken = parent::create($payload, $signatures, $jws_serialization_mode, $jweSharedProtectedHeader, $jweSharedHeader, $recipients, $jwe_serialization_mode, $aad);
40
        $this->eventDispatcher->dispatch(new NestedTokenIssuedEvent($nestedToken));
41
42
        return $nestedToken;
43
    }
44
}
45