Filters::bingbot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace PiedWeb\LogsAnalyzer;
4
5
class Filters
6
{
7
    public static $cacheIpGoogle;
8
9
    public static function googlebot($line)
10
    {
11
        return false !== stripos($line->getUserAgent(), 'googlebot');
12
    }
13
14
    /**
15
     * Strict means we check the ip too.
16
     */
17
    public static function googlebotStrict($line)
18
    {
19
        if (false !== stripos($line->getUserAgent(), 'googlebot')) {
20
            if (! isset(self::$cacheIpGoogle[$line->getIp()])) {
21
                self::$cacheIpGoogle[$line->getIp()] = false !== strpos(gethostbyaddr($line->getIp()), 'googlebot');
22
            }
23
24
            return self::$cacheIpGoogle[$line->getIp()];
25
        }
26
27
        return false;
28
    }
29
30
    public static function bingbot($line)
31
    {
32
        return false !== stripos($line->getUserAgent(), 'bingbot');
33
    }
34
}
35