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
Pull Request — master (#19)
by Toby
24:19
created

ExportManager::createAirtableDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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\Airtable\AirtableHandler;
0 ignored issues
show
Bug introduced by
The type BristolSU\ControlDB\Expo...irtable\AirtableHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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