XFrameOptionsHeader::hasAllowFrom()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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\Header;
9
10
use nicoSWD\SecHeaderCheck\Domain\Result\Result\XFrameOptionsHeaderResult;
11
use nicoSWD\SecHeaderCheck\Domain\Validator\AbstractHeaderParser;
12
13
final class XFrameOptionsHeader extends AbstractHeaderParser
14
{
15
    private const OPTION_DENY = 'deny';
16
    private const OPTION_SAME_ORIGIN = 'sameorigin';
17
18 8
    public function parse(): XFrameOptionsHeaderResult
19
    {
20 8
        return (new XFrameOptionsHeaderResult($this->getName(), $this->getValue()))
21 8
            ->setHasSecureOrigin($this->isSecureOrigin())
22 8
            ->setHasAllowFrom($this->hasAllowFrom());
23
    }
24
25 8
    private function isSecureOrigin(): bool
26
    {
27 8
        $value = strtolower($this->getValue());
28
29 8
        return $value === self::OPTION_DENY || $value === self::OPTION_SAME_ORIGIN;
30
    }
31
32 8
    private function hasAllowFrom(): bool
33
    {
34 8
        return strpos(strtolower($this->getValue()), 'allow-from ') === 0;
35
    }
36
}
37