Test Failed
Push — master ( 0c6ae7...5a133e )
by Yaroslav
02:43
created

GeoDataImporter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A truncateStorage() 0 3 1
A storeFileFromUrl() 0 11 4
A extractFile() 0 3 1
1
<?php
2
3
namespace LaraGeoData;
4
5
use Illuminate\Contracts\Container\Container;
6
use LaraGeoData\Storage\FilesystemStorage;
7
8
class GeoDataImporter
9
{
10
    protected FilesystemStorage $storage;
11
12 4
    public function __construct(Container $app)
13
    {
14 4
        $this->storage = new FilesystemStorage($app['files'], $app['config']->get('geonames.storage.path'));
15 4
    }
16
17 4
    public function storeFileFromUrl(string $url, ?string $name, ?\Closure $progressCallback = null, bool $force = false): bool
18
    {
19 4
        if (!($exists = $this->storage->exists($name)) || $force) {
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type null; however, parameter $filePath of LaraGeoData\Storage\FilesystemStorage::exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        if (!($exists = $this->storage->exists(/** @scrutinizer ignore-type */ $name)) || $force) {
Loading history...
20 3
            if ($exists) {
21 1
                $this->storage->delete($name);
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type null; however, parameter $filePath of LaraGeoData\Storage\FilesystemStorage::delete() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
                $this->storage->delete(/** @scrutinizer ignore-type */ $name);
Loading history...
22
            }
23
24 3
            return $this->storage->storeFromUrl($url, $name, $progressCallback);
25
        }
26
27 2
        return false;
28
    }
29
30
    /**
31
     * @param string $file
32
     *
33
     * @return bool
34
     * @throws \Exception
35
     */
36 1
    public function extractFile(string $file): bool
37
    {
38 1
        return $this->storage->extractZipFile($file);
39
    }
40
41
    /**
42
     * @return bool
43
     * @throws \Exception
44
     */
45 4
    public function truncateStorage(): bool
46
    {
47 4
        return $this->storage->truncate();
48
    }
49
}
50