Completed
Push — master ( 75955e...d5bb65 )
by Freek
01:22
created

PolicyFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 3
1
<?php
2
3
namespace Spatie\Csp;
4
5
use Spatie\Csp\Policies\Policy;
6
use Spatie\Csp\Exceptions\InvalidCspPolicy;
7
8
class PolicyFactory
9
{
10
    public static function create(string $className): Policy
11
    {
12
        $policy = app($className);
13
14
        if (! is_a($policy, Policy::class, true)) {
15
            throw InvalidCspPolicy::create($policy);
16
        }
17
18
        if (! empty(config('csp.report_uri'))) {
19
            $policy->reportTo(config('csp.report_uri'));
20
        }
21
22
        return $policy;
23
    }
24
}
25