Directive::isValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Csp;
4
5
use ReflectionClass;
6
7
abstract class Directive
8
{
9
    const BASE = 'base-uri';
10
    const BLOCK_ALL_MIXED_CONTENT = 'block-all-mixed-content';
11
    const CHILD = 'child-src';
12
    const CONNECT = 'connect-src';
13
    const DEFAULT = 'default-src';
14
    const FONT = 'font-src';
15
    const FORM_ACTION = 'form-action';
16
    const FRAME = 'frame-src';
17
    const FRAME_ANCESTORS = 'frame-ancestors';
18
    const IMG = 'img-src';
19
    const MANIFEST = 'manifest-src';
20
    const MEDIA = 'media-src';
21
    const OBJECT = 'object-src';
22
    const PLUGIN = 'plugin-types';
23
    const REPORT = 'report-uri';
24
    const REPORT_TO = 'report-to';
25
    const SANDBOX = 'sandbox';
26
    const SCRIPT = 'script-src';
27
    const SCRIPT_ATTR = 'script-src-attr';
28
    const SCRIPT_ELEM = 'script-src-elem';
29
    const STYLE = 'style-src';
30
    const STYLE_ATTR = 'style-src-attr';
31
    const STYLE_ELEM = 'style-src-elem';
32
    const UPGRADE_INSECURE_REQUESTS = 'upgrade-insecure-requests';
33
    const WEB_RTC = 'webrtc-src';
34
    const WORKER = 'worker-src';
35
36
    public static function isValid(string $directive): bool
37
    {
38
        $constants = (new ReflectionClass(static::class))->getConstants();
39
40
        return in_array($directive, $constants);
41
    }
42
}
43