GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0994ac...8bf298 )
by Martin
04:01
created

AbstractProvider::getComposerPackages()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0313

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 9.2
cc 4
eloc 8
nc 3
nop 0
crap 4.0313
1
<?php
2
namespace UserAgentParser\Provider;
3
4
use UserAgentParser\Exception;
5
use UserAgentParser\Result;
6
7
abstract class AbstractProvider
8
{
9
    private $version;
10
11
    protected $defaultValues = [];
12
13
    /**
14
     * Return the name of the provider
15
     *
16
     * @return string
17
     */
18
    abstract public function getName();
19
20
    abstract public function getComposerPackageName();
21
22
    /**
23
     * Return the version of the provider
24
     *
25
     * @return string null
26
     */
27 2
    public function getVersion()
28
    {
29 2
        if ($this->version !== null) {
30 1
            return $this->version;
31
        }
32
33 2
        if ($this->getComposerPackageName() === null) {
34 1
            return;
35
        }
36
37 2
        $packages = $this->getComposerPackages();
38
39 2
        if ($packages === null) {
40 1
            return;
41
        }
42
43 2
        foreach ($packages as $package) {
0 ignored issues
show
Bug introduced by
The expression $packages of type object<stdClass> is not traversable.
Loading history...
44 2
            if ($package->name === $this->getComposerPackageName()) {
45 1
                $this->version = $package->version;
46
47 2
                break;
48
            }
49 2
        }
50
51 2
        return $this->version;
52
    }
53
54
    /**
55
     *
56
     * @return \stdClass null
57
     */
58 2
    private function getComposerPackages()
59
    {
60 2
        if (! file_exists('composer.lock')) {
61 1
            return;
62
        }
63
64 2
        $content = file_get_contents('composer.lock');
65 2
        if ($content === false || $content === '') {
66
            return;
67
        }
68
69 2
        $content = json_decode($content);
70
71 2
        return $content->packages;
72
    }
73
74
    /**
75
     *
76
     * @param  mixed   $value
77
     * @param  array   $additionalDefaultValues
78
     * @return boolean
79
     */
80 2
    protected function isRealResult($value, array $additionalDefaultValues = [])
81
    {
82 2
        if ($value === '' || $value === null) {
83 1
            return false;
84
        }
85
86 2
        $value = (string) $value;
87
88 2
        $defaultValues = array_merge($this->defaultValues, $additionalDefaultValues);
89
90 2
        if (in_array($value, $defaultValues, true) === true) {
91 1
            return false;
92
        }
93
94 2
        return true;
95
    }
96
97
    /**
98
     *
99
     * @param string $userAgent
100
     * @param array  $headers
101
     *
102
     * @throws Exception\NoResultFoundException
103
     *
104
     * @return Result\UserAgent
105
     */
106
    abstract public function parse($userAgent, array $headers = []);
107
}
108