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.

Jws   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getUnsignedValue() 10 10 1
A sign() 0 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Emarref\Jwt\Signature;
4
5
use Emarref\Jwt\Encoding\EncoderInterface;
6
use Emarref\Jwt\Encryption\EncryptionInterface;
7
use Emarref\Jwt\HeaderParameter\Algorithm;
8
use Emarref\Jwt\Token;
9
10
class Jws implements SignerInterface
11
{
12
    /**
13
     * @var EncryptionInterface
14
     */
15
    private $encryption;
16
17
    /**
18
     * @var EncoderInterface
19
     */
20
    private $encoder;
21
22
    public function __construct(EncryptionInterface $encryption, EncoderInterface $encoder)
23
    {
24
        $this->encryption = $encryption;
25
        $this->encoder    = $encoder;
26
    }
27
28 View Code Duplication
    public function getUnsignedValue(Token $token)
29
    {
30
        $jsonHeader    = $token->getHeader()->getParameters()->jsonSerialize();
31
        $encodedHeader = $this->encoder->encode($jsonHeader);
32
33
        $jsonPayload    = $token->getPayload()->getClaims()->jsonSerialize();
34
        $encodedPayload = $this->encoder->encode($jsonPayload);
35
36
        return sprintf('%s.%s', $encodedHeader, $encodedPayload);
37
    }
38
39
    public function sign(Token $token)
40
    {
41
        $token->addHeader(new Algorithm($this->encryption->getAlgorithmName()));
42
43
        $rawSignature = $this->getUnsignedValue($token);
44
45
        $signature = $this->encryption->encrypt($rawSignature);
46
47
        $token->setSignature($signature);
48
    }
49
}
50