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

DeviceDetector::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 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
}