Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| CspNonceExtension | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFunctions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getCspNonce | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Shared\View; |
| 6 | |
| 7 | use App\Shared\Security\CspNonceService; |
| 8 | use Twig\Extension\AbstractExtension; |
| 9 | use Twig\TwigFunction; |
| 10 | |
| 11 | class CspNonceExtension extends AbstractExtension |
| 12 | { |
| 13 | public function __construct( |
| 14 | private CspNonceService $nonceService |
| 15 | ) {} |
| 16 | |
| 17 | public function getFunctions(): array |
| 18 | { |
| 19 | return [ |
| 20 | new TwigFunction('csp_nonce', [$this, 'getCspNonce']), |
| 21 | ]; |
| 22 | } |
| 23 | |
| 24 | public function getCspNonce(): string |
| 25 | { |
| 26 | return $this->nonceService->getNonce(); |
| 27 | } |
| 28 | } |