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

DeviceDetector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 63.64 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 21
loc 33
rs 10
c 0
b 0
f 0

3 Methods

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

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 DeviceDetector extends BrowserDetector
9
{
10
    public function detect(string $ua)
11
    {
12
        $this->config = $this->detector->getPatternList($this->detector->getDataProvider()->getConfig(), 'device');
13
        $this->initResultObject();
14
        $this->setupResultObject();
15
    }
16
17
18 View Code Duplication
    private function initResultObject()
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
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()->getDevice();
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
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
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()->getDevice();
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
}