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.

Context   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 37
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 16 3
A newContext() 0 4 1
1
<?php
2
3
namespace Saltwater\Root\Provider;
4
5
use Saltwater\Server as S;
6
use Saltwater\Utils as U;
7
use Saltwater\Salt\Provider;
8
use Saltwater\Salt\Context as SwContext;
9
use Saltwater\Salt\Module;
10
11
class Context extends Provider
12
{
13
    /**
14
     * @param string         $name
15
     * @param SwContext|null $parent
16
     *
17
     * @return SwContext|null
18
     */
19
    public function get($name, $parent = null)
20
    {
21
        $module = S::$n->getContextModule($name);
22
23
        if (empty($module)) {
24
            return null;
25
        }
26
27
        $class = U::className($module::getNamespace(), 'context', $name);
28
29
        if (!class_exists($class)) {
30
            return null;
31
        }
32
33
        return $this->newContext($class, $parent, $module);
0 ignored issues
show
Bug introduced by
It seems like $module defined by \Saltwater\Server::$n->getContextModule($name) on line 21 can also be of type string; however, Saltwater\Root\Provider\Context::newContext() does only seem to accept object<Saltwater\Salt\Module>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
34
    }
35
36
    /**
37
     * @param string         $class
38
     * @param SwContext|null $parent
39
     * @param Module         $module
40
     *
41
     * @return SwContext
42
     */
43
    private function newContext($class, $parent, $module)
44
    {
45
        return new $class($parent, $module);
46
    }
47
}
48