Passed
Push — master ( 610dd1...d8a0ed )
by Yaroslav
03:07
created

GeoDataImporter::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaraGeoData;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Support\Str;
7
use LaraGeoData\Storage\FilesystemStorage;
8
9
/**
10
 * @method bool storageCreateFromUrl(string $url, ?string $name, ?\Closure $progressCallback = null, bool $force = false)
11
 * @method bool storageExtractZipFile(string $file)
12
 * @method bool storageTruncate()
13
 */
14
class GeoDataImporter
15
{
16
    protected FilesystemStorage $storage;
17
18 7
    public function __construct(Container $app)
19
    {
20 7
        $this->storage = new FilesystemStorage($app['files'], $app['config']->get('geonames.storage.path'));
21 7
    }
22
23
    /**
24
     * Dynamically forward call.
25
     *
26
     * @param  string  $method
27
     * @param  array  $parameters
28
     * @return mixed
29
     */
30 6
    public function __call($method, $parameters)
31
    {
32 6
        if (Str::startsWith($method, 'storage')) {
33 5
            $realMethodName = lcfirst(Str::after($method, 'storage'));
34 5
            if (method_exists($this->storage, $realMethodName)) {
35 4
                return $this->storage->{$realMethodName}(...$parameters);
36
            }
37
        }
38
39 2
        throw new \BadMethodCallException("Method [{$method}] not exists.");
40
    }
41
42
    /**
43
     * Get current storage instance.
44
     *
45
     * @return FilesystemStorage
46
     */
47 1
    public function storage(): FilesystemStorage
48
    {
49 1
        return $this->storage;
50
    }
51
}
52