Completed
Push — 4.0 ( c710b5...5960ab )
by Serhii
02:22
created

Tools   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersion() 0 16 2
A getVersionPattern() 0 4 1
A getWindowsVersion() 0 4 2
1
<?php
2
/**
3
 * @author Serhii Nekhaienko <[email protected]>
4
 * @license GPL
5
 * @copyright Serhii Nekhaienko &copy 2018
6
 * @version 4.0.0
7
 * @project browser-detector
8
 */
9
10
namespace EndorphinStudio\Detector;
11
12
class Tools
13
{
14
    public static function getVersion(string $phrase, string $ua): string
15
    {
16
        $version = static::getVersionPattern($phrase);
17
        $uaString = str_replace(' NT', '', $ua);
18
        if (preg_match($version, $uaString)) {
19
            preg_match($version, $uaString, $v);
20
            $version = $v[0];
21
            $version = preg_replace('/' . $phrase . '/', '', $version);
22
            $version = str_replace(';', '', $version);
23
            $version = str_replace(' ', '', $version);
24
            $version = str_replace('/', '', $version);
25
            $version = str_replace('_', '.', $version);
26
27
            return $version;
28
        }
29
    }
30
31
    public static function getVersionPattern(string $phrase): string
32
    {
33
        return sprintf('\'/\'%s\'(\/| )[\w-._]{1,15}/\'', $phrase);
34
    }
35
36
    public static function getWindowsVersion(string $version, array $config)
37
    {
38
        return array_key_exists($version, $config) ? $config[$version] : $version;
39
    }
40
}