ParseHeaderSectionTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D parseHeaderDataSet() 0 30 9
1
<?php
2
declare(strict_types=1);
3
4
namespace Crossjoin\Browscap\Source\Ini;
5
6
use Crossjoin\Browscap\Source\DataSet;
7
use Crossjoin\Browscap\Type;
8
9
/**
10
 * Trait ParseHeaderSectionTrait
11
 *
12
 * @package Crossjoin\Browscap\Source\Ini
13
 * @author Christoph Ziegenberg <[email protected]>
14
 * @link https://github.com/crossjoin/browscap
15
 */
16
trait ParseHeaderSectionTrait
17
{
18
    /**
19
     * @param DataSet $dataSet
20
     *
21
     * @return array
22
     */
23
    protected function parseHeaderDataSet(DataSet $dataSet)
24
    {
25
        $result = ['version' => 0, 'released' => 0, 'type' => Type::UNKNOWN];
26
27
        $properties = $dataSet->getProperties();
28
29
        if ($properties !== false) {
30
            if (array_key_exists('Version', $properties) && ctype_digit($properties['Version'])) {
31
                $result['version'] = (int)$properties['Version'];
32
            }
33
            if (array_key_exists('Released', $properties)) {
34
                $result['released'] = (int)strtotime($properties['Released']);
35
            }
36
            if (array_key_exists('Type', $properties)) {
37
                switch (strtolower($properties['Type'])) {
38
                    case 'full':
39
                        $result['type'] = Type::FULL;
40
                        break;
41
                    case 'lite':
42
                        $result['type'] = Type::LITE;
43
                        break;
44
                    case '':
45
                        $result['type'] = Type::STANDARD;
46
                        break;
47
                }
48
            }
49
        }
50
51
        return $result;
52
    }
53
}
54