CookieGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Mercure;
4
5
use Lcobucci\JWT\Builder;
6
use Lcobucci\JWT\Signer\Hmac\Sha256;
7
use Lcobucci\JWT\Signer\Key;
8
use Symfony\Component\HttpFoundation\Cookie;
9
10
final class CookieGenerator
11
{
12
    private $secret;
13
14
    public function __construct(string $secret)
15
    {
16
        $this->secret = $secret;
17
    }
18
19
    public function generate(): Cookie
20
    {
21
        $token = (new Builder())
22
            ->withClaim('mercure', ['subscribe' => ['*']])
23
            ->getToken(new Sha256(), new Key($this->secret));
24
25
        return Cookie::create('mercureAuthorization', $token, 0, '/.well-known/mercure');
26
    }
27
}
28