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

GeoDataImporter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __call() 0 10 3
A storage() 0 3 1
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