Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
CspNonceService
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 getNonce
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Shared\Security;
6
7use Exception;
8
9 class CspNonceService
10{
11    private ?string $nonce = null;
12
13    /**
14     * Zwraca wygenerowany nonce dla obecnego żądania HTTP.
15     * Jeżeli nie istnieje, generuje go jednorazowo.
16     *
17     * @return string
18     * @throws Exception
19     */
20    public function getNonce(): string
21    {
22        if ($this->nonce === null) {
23            $this->nonce = base64_encode(random_bytes(16));
24        }
25
26        return $this->nonce;
27    }
28}