Completed
Push — master ( cda577...82aa13 )
by Christian
02:25
created

XFrameOptionsCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkEnv() 0 15 4
1
<?php
2
3
namespace N98\Magento\Command\System\Check\Env;
4
5
use N98\Magento\Command\System\Check\Result;
6
7
class XFrameOptionsCheck extends CheckAbstract
8
{
9
    /**
10
     * Check if x-frame-options has correct value
11
     */
12
    public function checkEnv()
13
    {
14
        $result = $this->_results->createResult();
15
        $xFrameOptions = strtolower($this->_env['x-frame-options']);
16
        if (in_array($xFrameOptions, ['deny', 'sameorigin']) || strpos($xFrameOptions, 'allow-from') !== false || $xFrameOptions == '*') {
17
            $status = Result::STATUS_OK;
18
            $message = '<info><comment>x-frame-options</comment> has correct value.</info>';
19
        } else {
20
            $status = Result::STATUS_ERROR;
21
            $message = "<error><comment>x-frame-options</comment> has incorrect value. It should be either 'deny', 'sameorigin', '*' or 'allow-from https://hostname'.</error>";
22
        }
23
24
        $result->setStatus($status);
25
        $result->setMessage($message);
26
    }
27
}
28