CloudFlare::detect()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 3
1
<?php
2
/**
3
 * This file is part of SHIELDFY Web Application Firewall Detector.
4
 * (c) 2016 SHIELDFY, All rights reserved.
5
 *
6
 * The code provided was developed by Matthias "Nihylum" Kaschubowski
7
 *
8
 * The applied license is stored at the root directory of this package.
9
 */
10
namespace Shieldfy\Firewall;
11
12
use Shieldfy\FirewallInterface;
13
14
/**
15
 * CloudFlare Firewall Class.
16
 *
17
 * @package shieldfy.waf-detector
18
 *
19
 * @author  Matthias Kaschubowski <[email protected]>
20
 */
21
class CloudFlare implements FirewallInterface
22
{
23
    /**
24
     * returns the name of the firewall.
25
     *
26
     * @return string
27
     */
28
    public function getName()
29
    {
30
        return 'CloudFlare';
31
    }
32
33
    /**
34
     * detects whether the provided headers and body string does match the firewall identification rules or not.
35
     *
36
     * @param string[] $headers
37
     * @param string   $bodyString
38
     * @param string   $url
39
     *
40
     * @return bool
41
     */
42
    public function detect(array $headers, $bodyString, $url)
43
    {
44
        if (array_key_exists('server', $headers) && strtolower($headers['server']) === 'cloudflare-nginx') {
45
            return true;
46
        }
47
48
        if (array_key_exists('cf-ray', $headers)) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return array_key_exists('cf-ray', $headers);.
Loading history...
49
            return true;
50
        }
51
52
        return false;
53
    }
54
}
55