UserAgentStrategy::getUserAgent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Humweb\Features\Strategy;
4
5
/**
6
 * User agent strategy.
7
 */
8
class UserAgentStrategy extends AbstractStrategy
9
{
10
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function handle($args = [])
15
    {
16
        $userAgent = $this->getUserAgent();
17
18
        foreach ($args['patterns'] as $pattern) {
19
            if (preg_match($pattern, $userAgent)) {
20
                return true;
21
            }
22
        }
23
24
        return false;
25
    }
26
27
28
    /**
29
     * Returns current user agent.
30
     *
31
     * @return string
32
     */
33
    public function getUserAgent()
34
    {
35
        return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
36
    }
37
}
38