GeoDataImporter   A
last analyzed

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 storagePath(string $file)
13
 * @method bool storageTruncate()
14
 */
15
class GeoDataImporter
16
{
17
    protected FilesystemStorage $storage;
18
19 16
    public function __construct(Container $app)
20
    {
21 16
        $this->storage = new FilesystemStorage($app['files'], $app['config']->get('geonames.storage.path'));
22 16
    }
23
24
    /**
25
     * Dynamically forward call.
26
     *
27
     * @param  string  $method
28
     * @param  array  $parameters
29
     * @return mixed
30
     */
31 15
    public function __call($method, $parameters)
32
    {
33 15
        if (Str::startsWith($method, 'storage')) {
34 14
            $realMethodName = lcfirst(Str::after($method, 'storage'));
35 14
            if (method_exists($this->storage, $realMethodName)) {
36 13
                return $this->storage->{$realMethodName}(...$parameters);
37
            }
38
        }
39
40 2
        throw new \BadMethodCallException("Method [{$method}] not exists.");
41
    }
42
43
    /**
44
     * Get current storage instance.
45
     *
46
     * @return FilesystemStorage
47
     */
48 1
    public function storage(): FilesystemStorage
49
    {
50 1
        return $this->storage;
51
    }
52
}
53