Filters::googlebotStrict()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 10
cc 3
nc 3
nop 1
crap 12
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