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.

ServiceChain   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 8
dl 0
loc 117
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 14 2
A chain() 0 12 3
A explode() 0 19 4
A explodePush() 0 14 2
A push() 0 19 3
1
<?php
2
3
namespace Saltwater\App\Provider;
4
5
use Saltwater\Bus\Water\Chain;
6
use Saltwater\Salt\Provider;
7
use Saltwater\Server as S;
8
use Saltwater\Utils as U;
9
use Saltwater\Salt\Service;
10
use Saltwater\Salt\Context;
11
12
class ServiceChain extends Provider
13
{
14
    private $chain;
15
16
    public function __construct()
17
    {
18
        $this->chain = new Chain();
19
    }
20
21
    public function resolve($input, $result = null)
22
    {
23
        $length = count($this->chain);
24
25
        $service = new Service;
26
27
        for ($i = 0; $i < $length; ++$i) {
28
            $result = $this->chain(
29
                $service, $this->chain[$i], $input, $result, ($i == $length - 1)
30
            );
31
        }
32
33
        return $result;
34
    }
35
36
    /**
37
     * @param Service $service
38
     * @param object  $item
39
     * @param mixed   $input
40
     * @param mixed   $result
41
     * @param bool    $last
42
     *
43
     * @return mixed|null
44
     */
45
    private function chain(&$service, &$item, $input, $result, $last)
46
    {
47
        $item->context->pushData($result);
48
49
        $service->setContext($item->context);
50
51
        if (!$service->prepareCall($item)) {
52
            $service = S::$n->service->get($item->service, $item->context);
53
        }
54
55
        return $service->call($item, $last ? $input : null);
56
    }
57
58
    /**
59
     * @param Context $context
60
     * @param string  $cmd
61
     * @param array   $path
62
     */
63
    protected function explode($context, $cmd, $path)
64
    {
65
        $root = array_shift($path);
66
67
        // This is for simple commands upon an established service
68
        if (empty($path) && !empty($this->chain)) {
69
            $this->push($context, $cmd, $root);
70
71
            return;
72
        }
73
74
        if ($c = S::$n->context->get($root, $context)) {
75
            $context = $c;
76
77
            $root = array_shift($path);
78
        }
79
80
        $this->explodePush($path, $context, $cmd, $root);
81
    }
82
83
    /**
84
     * @param Context $context
85
     * @param string  $cmd
86
     */
87
    private function explodePush($path, $context, $cmd, $root)
88
    {
89
        $next = array_shift($path);
90
91
        // Either push a call on the last service or a new one into the chain
92
        if (empty($path)) {
93
            $this->push($context, $cmd, $root, $next);
94
        } else {
95
            $this->push($context, 'get', $root, $next);
96
97
            // We have leftovers!
98
            $this->explode($context, $cmd, $path);
99
        }
100
    }
101
102
    /**
103
     * @param Context $context
104
     * @param string  $cmd
105
     * @param string  $service
106
     * @param string  $path
107
     */
108
    protected function push($context, $cmd, $service, $path = null)
109
    {
110
        $method = $service;
111
112
        if (!empty($path) && !is_numeric($path)) {
113
            $method = $path;
114
115
            $path = null;
116
        }
117
118
        $this->chain[] = (object) array(
119
            'context'  => $context,
120
            'http'     => $cmd,
121
            'service'  => $service,
122
            'method'   => $method,
123
            'function' => $cmd . U::dashedToCamelCase($method),
124
            'path'     => $path
125
        );
126
    }
127
128
}
129