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.

Navigator   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __get() 0 4 1
A __call() 0 6 2
A storeCache() 0 10 2
A loadCache() 0 10 2
A getContextModule() 0 8 1
A provider() 0 15 3
1
<?php
2
3
namespace Saltwater\Water;
4
5
use Saltwater\Server as S;
6
use Saltwater\Salt\Module;
7
use Saltwater\Salt\Provider;
8
9
/**
10
 * Class Navigator
11
 *
12
 * @package Saltwater\Water
13
 *
14
 * List of known providers:
15
 *
16
 * @property \Saltwater\Root\Provider\Context   $context
17
 * @property \Saltwater\RedBean\Provider\Entity $entity
18
 * @property \Saltwater\Root\Provider\Service   $service
19
 *
20
 * @property \RedBean_Instance                  $db
21
 *
22
 * @property \Saltwater\RedBean\Provider\Log    $log
23
 * @property \Saltwater\App\Provider\Response   $response
24
 * @property \Saltwater\App\Provider\Route      $route
25
 *
26
 * @property \Saltwater\App\Common\Config       $config
27
 *
28
 * Same as the above, but as methods for injecting a caller
29
 *
30
 * @method \Saltwater\Root\Provider\Context     context($caller = null)
31
 * @method \Saltwater\RedBean\Provider\Entity   entity($caller = null)
32
 * @method \Saltwater\Root\Provider\Service     service($caller = null)
33
 *
34
 * @method \RedBean_Instance db($caller = null)
35
 *
36
 * @method \Saltwater\RedBean\Provider\Log      log($caller = null)
37
 * @method \Saltwater\App\Provider\Response     response($caller = null)
38
 * @method \Saltwater\App\Provider\Route        route($caller = null)
39
 *
40
 * @method \Saltwater\App\Common\Config         config($caller = null)
41
 */
42
class Navigator
43
{
44
    /** @var ModuleStack */
45
    public $modules = array();
46
47
    /** @var Registry */
48
    public $registry = array();
49
50
    /**
51
     * Initiate the navigator by setting up a ModuleStack and a Registry
52
     *
53
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
54
     */
55
    public function __construct()
56
    {
57
        $this->modules = new ModuleStack();
58
59
        $this->registry = new Registry();
60
    }
61
62
    /**
63
     * Magic property to get a provider without a preset caller
64
     *
65
     * @param string $type
66
     *
67
     * @return Provider
68
     */
69
    public function __get($type)
70
    {
71
        return $this->provider($type);
72
    }
73
74
    /**
75
     * Magic function to get a provider with a preset caller
76
     *
77
     * @param string $type
78
     * @param mixed  $args
79
     *
80
     * @return Provider
81
     */
82
    public function __call($type, $args)
83
    {
84
        $caller = empty($args) ? null : array_shift($args);
85
86
        return $this->provider($type, $caller);
87
    }
88
89
    /**
90
     * Store the navigator within a cache file
91
     *
92
     * @param string $path
93
     */
94
    public function storeCache($path)
95
    {
96
        $info = pathinfo($path);
97
98
        if (!is_dir($info['dirname'])) {
99
            mkdir($info['dirname'], 0744, true);
100
        }
101
102
        return file_put_contents($path, serialize($this));
103
    }
104
105
    /**
106
     * Recreate the navigator from a cache file
107
     *
108
     * @param string $path
109
     *
110
     * @return bool
111
     */
112
    public function loadCache($path)
113
    {
114
        $cache = unserialize(file_get_contents($path));
115
116
        foreach ($cache as $k => $v) {
117
            $this->$k = $v;
118
        }
119
120
        return true;
121
    }
122
123
    /**
124
     * Get the Module that provides a context
125
     *
126
     * @param string $name plain name of the context
127
     *
128
     * @return Module|null
129
     */
130
    public function getContextModule($name)
131
    {
132
        return $this->modules->get(
133
            $this->modules->finder->getSaltModule(
0 ignored issues
show
Bug introduced by
The method getSaltModule() does not seem to exist on object<Saltwater\Water\ModuleFinder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
                $this->registry->bit('context.' . $name)
135
            )
136
        );
137
    }
138
139
    /**
140
     * Generic call for a type of provider
141
     *
142
     * @param string $type
143
     * @param string $caller Caller module name
144
     *
145
     * @return Provider
146
     */
147
    public function provider($type, $caller = null)
148
    {
149
        $salt = 'provider.' . $type;
150
151
        if (!$bit = $this->registry->bit($salt)) {
152
            S::halt(500, 'provider does not exist: ' . $type);
153
        };
154
155
        if (empty($caller)) {
156
            $caller = $this->modules->finder->find(Backtrace::lastCaller(),
0 ignored issues
show
Bug introduced by
It seems like \Saltwater\Water\Backtrace::lastCaller() targeting Saltwater\Water\Backtrace::lastCaller() can also be of type string; however, Saltwater\Water\ModuleFinder::find() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
157
                $salt);
158
        }
159
160
        return $this->modules->finder->provider($bit, $caller, $type);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->modules->finder->...($bit, $caller, $type); of type boolean|Saltwater\Salt\Provider adds the type boolean to the return on line 160 which is incompatible with the return type documented by Saltwater\Water\Navigator::provider of type Saltwater\Salt\Provider.
Loading history...
161
    }
162
}
163