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   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 53
loc 53
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 7 7 1
A getServiceClass() 11 11 2
A getServiceClassFallback() 20 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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