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.

Service::getServiceClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Saltwater\Capability\Provider;
4
5
use Saltwater\Utils as U;
6
use Saltwater\Salt\Provider;
7
use Saltwater\Salt\Context as SwContext;
8
use Saltwater\Salt\Service as SwService;
9
10 View Code Duplication
class Service extends Provider
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /**
13
     * @param string    $name
14
     * @param SwContext $context
15
     *
16
     * @return SwService
17
     */
18
    public function get($name, $context)
19
    {
20
        $class = $this->getServiceClass($context, $name);
21
22
        // TODO: RB Fallback is rather dirty, try parent context or fail out
23
        return new $class($context);
24
    }
25
26
    /**
27
     * @param SwContext $context
28
     * @param string    $service
29
     */
30
    private function getServiceClass($context, $service)
31
    {
32
        // See whether the current context namespace has this service
33
        $class = U::className($context->namespace, 'service', $service);
34
35
        if (class_exists($class)) {
36
            return $class;
37
        }
38
39
        return $this->getServiceClassFallback($context, $service);
40
    }
41
42
    private function getServiceClassFallback($context, $service)
43
    {
44
        // Check whether we have a RestService in the context namespace
45
        $class = U::className($context->namespace, 'service', 'rest');
46
47
        if (class_exists($class)) {
48
            return $class;
49
        }
50
51
        // Next up, try for a root service
52
        $class = U::className('saltwater', 'root', 'service', $service);
53
54
        if (class_exists($class)) {
55
            return $class;
56
        }
57
58
        // Fall back to the RedBean RestService
59
        // TODO: Needs to be decoupled
60
        return 'Saltwater\RedBean\Service\Rest';
61
    }
62
}
63