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

BrowserDetector   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 47
Duplicated Lines 72.34 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 34
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A detect() 0 6 1
A initResultObject() 9 9 2
A setupResultObject() 12 12 3
A detectByType() 13 13 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}