Completed
Push — 4.0 ( 604d5a...33061c )
by Serhii
02:27
created

BrowserDetector::initResultObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace EndorphinStudio\Detector\Detection;
5
6
use EndorphinStudio\Detector\Tools;
7
8
class BrowserDetector extends AbstractDetection
9
{
10
    public function detect(string $ua)
11
    {
12
        $this->config = $this->detector->getPatternList($this->detector->getDataProvider()->getConfig(), 'browser');
13
        $this->initResultObject();
14
        $this->setupResultObject();
15
    }
16
17
18 View Code Duplication
    private function initResultObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $result = $this->detector->getResultObject()->getBrowser();
21
22
        // init default value from data
23
        foreach ($this->config['default'] as $defaultKey => $defaultValue) {
24
            Tools::runSetter($result, $defaultKey, $defaultValue);
25
        }
26
    }
27
28 View Code Duplication
    private function setupResultObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $result = $this->detector->getResultObject()->getBrowser();
31
        $browserData = $this->detectByType();
32
        foreach ($browserData as $key => $value) {
33
            if ($key === 'originalInfo') {
34
                $this->setAttributes($value);
35
                continue;
36
            }
37
            Tools::runSetter($result, $key, $value);
38
        }
39
    }
40
41 View Code Duplication
    protected function detectByType(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        foreach ($this->config as $type => $patternList) {
44
            if ($type === 'default') {
45
                continue;
46
            }
47
            $browser = $this->detectByPattern($patternList);
48
            if ($browser) {
49
                return array_merge($browser, ['type' => $type]);
50
            }
51
        }
52
        return [];
53
    }
54
}