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.
Passed
Push — master ( 18e39d...348781 )
by Toby
36:48 queued 23:00
created

ExportManager::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\ControlDB\Export;
4
5
use BristolSU\ControlDB\Export\Handler\DumpHandler;
6
use BristolSU\ControlDB\Export\Handler\Handler;
7
use BristolSU\ControlDB\Export\Handler\SaveCsvHandler;
8
use Closure;
9
use Illuminate\Contracts\Container\Container;
10
use Illuminate\Support\Str;
11
use InvalidArgumentException;
12
13
class ExportManager
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ExportManager
Loading history...
14
{
15
16
    /**
17
     * The container instance.
18
     *
19
     * @var Container
20
     */
21
    protected $container;
22
23
    /**
24
     * The registered custom driver creators.
25
     *
26
     * @var array
27
     */
28
    protected $customCreators = [];
29
    
30
    protected $formatters = [];
31
32
    /**
33
     * Create a new Export manager instance.
34
     *
35
     * @param  Container  $container
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
36
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
37
     */
38 15
    public function __construct(Container $container)
39
    {
40 15
        $this->container = $container;
41 15
    }
42
43
    /**
44
     * Get a export driver instance.
45
     *
46
     * @param  string|null  $driver
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
47
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
48
     */
49 15
    public function driver($driver = null)
50
    {
51 15
        return $this->resolve($driver ?? $this->getDefaultDriver());
52
    }
53
54
    /**
55
     * Resolve the given export instance by name.
56
     *
57
     * @param  string  $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
58
     * @return Handler
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
59
     *
60
     * @throws \InvalidArgumentException
61
     */
62 15
    protected function resolve($name)
63
    {
64 15
        $config = $this->configurationFor($name);
65
66 15
        if (is_null($config)) {
0 ignored issues
show
introduced by
The condition is_null($config) is always false.
Loading history...
67 1
            throw new InvalidArgumentException("Exporter [{$name}] is not defined.");
68
        }
69 14
        if (isset($this->customCreators[$config['driver']])) {
70 8
            return $this->callCustomCreator($config);
71
        }
72
73 6
        $driverMethod = 'create'.Str::studly($config['driver']).'Driver';
74
75 6
        if (method_exists($this, $driverMethod)) {
76 5
            return $this->{$driverMethod}($config);
77
        }
78
79 1
        throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
80
    }
81
82
    /**
83
     * Call a custom driver creator.
84
     *
85
     * @param  array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
86
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
87
     */
88 8
    protected function callCustomCreator(array $config)
89
    {
90 8
        return $this->customCreators[$config['driver']]($this->container, $config);
91
    }
92
    
93
    /**
94
     * Get the export connection configuration.
95
     *
96
     * @param  string  $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
97
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
98
     */
99 15
    protected function configurationFor($name)
100
    {
101 15
        $config = $this->container['config']["control.export.{$name}"];
102 15
        if(is_null($config)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
103 1
            return null;
104
        }
105 14
        if(!isset($config['formatters'])) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
106 13
            $config['formatters'] = [];
107
        }
108 14
        foreach($this->formatters() as $formatter => $formatterConfig) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
109 2
            $config['formatters'][$formatter] = $formatterConfig;
110
        }
111
        
112 14
        return $config;
113
    }
114
115
    /**
116
     * Get the default export driver name.
117
     *
118
     * @return string
119
     */
120 6
    public function getDefaultDriver()
121
    {
122 6
        return $this->container['config']['control.export.default'];
123
    }
124
125
    /**
126
     * Register a custom driver creator Closure.
127
     *
128
     * @param  string  $driver
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 2 found
Loading history...
129
     * @param  \Closure  $callback
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
130
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
131
     */
132 8
    public function extend($driver, Closure $callback)
133
    {
134 8
        $this->customCreators[$driver] = $callback->bindTo($this, $this);
135
136 8
        return $this;
137
    }
138
139 2
    public function withFormatter(string $formatter, array $config = [])
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function withFormatter()
Loading history...
140
    {
141 2
        $this->formatters[$formatter] = $config;
142
        
143 2
        return $this;
144
    }
145
    
146
    /**
147
     * Dynamically call the default driver instance.
148
     *
149
     * @param  string  $method
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
150
     * @param  array  $parameters
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
151
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
152
     */
153 1
    public function __call($method, $parameters)
154
    {
155 1
        return $this->driver()->$method(...$parameters);
156
    }
157
158 1
    public function createDumpDriver(array $config)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function createDumpDriver()
Loading history...
159
    {
160 1
        return new DumpHandler($config);
161
    }
162
163 1
    public function createSaveCsvDriver(array $config)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function createSaveCsvDriver()
Loading history...
164
    {
165 1
        return new SaveCsvHandler($config);
166
    }
167
168 14
    protected function formatters()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function formatters()
Loading history...
169
    {
170 14
        return $this->formatters;
171
    }
172
173
}