CookieGenerator::generate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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