HeaderParserFactory::createFromHeader()   B
last analyzed

Complexity

Conditions 11
Paths 11

Size

Total Lines 25
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 14.8983

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 25
c 0
b 0
f 0
ccs 15
cts 22
cp 0.6818
rs 7.3166
cc 11
nc 11
nop 1
crap 14.8983

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
/**
4
 * @license  http://opensource.org/licenses/mit-license.php MIT
5
 * @link     https://github.com/nicoSWD
6
 * @author   Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\SecHeaderCheck\Domain\Validator;
9
10
use nicoSWD\SecHeaderCheck\Domain\Header\HttpHeader;
11
use nicoSWD\SecHeaderCheck\Domain\Header\SecurityHeader;
12
13
final class HeaderParserFactory
14
{
15 2
    public function createFromHeader(HttpHeader $header): AbstractHeaderParser
16
    {
17 2
        switch ($header->name()) {
18 1
            case SecurityHeader::STRICT_TRANSPORT_SECURITY:
19 2
                return new Header\StrictTransportSecurityHeader($header);
20 1
            case SecurityHeader::X_FRAME_OPTIONS:
21
                return new Header\XFrameOptionsHeader($header);
22 1
            case SecurityHeader::X_XSS_PROTECTION:
23
                return new Header\XXSSProtectionHeader($header);
24 1
            case SecurityHeader::X_CONTENT_TYPE_OPTIONS:
25
                return new Header\XContentTypeOptionsHeader($header);
26 1
            case SecurityHeader::REFERRER_POLICY:
27
                return new Header\ReferrerPolicyHeader($header);
28 1
            case SecurityHeader::SET_COOKIE:
29
                return new Header\SetCookieHeader($header);
30 1
            case SecurityHeader::SERVER:
31 2
                return new Header\ServerHeader($header);
32 1
            case SecurityHeader::X_POWERED_BY:
33
                return new Header\XPoweredByHeader($header);
34 1
            case SecurityHeader::CONTENT_SECURITY_POLICY:
35
                return new Header\ContentSecurityPolicyHeader($header);
36 1
            case SecurityHeader::EXPECT_CT:
37
                // Pending
38
            default:
39 2
                return new Header\NonSecurityHeader($header);
40
        }
41
    }
42
}
43