ValiableImportCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 34
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 4 1
A fire() 0 14 5
1
<?php
2
namespace Sonar\Valiable\Console;
3
4
use Illuminate\Console\Command;
5
use Illuminate\Filesystem\Filesystem;
6
7
use Sonar\Valiable\Valiable;
8
9
class ValiableImportCommand extends Command
10
{
11
    protected $name = 'valiable:import';
12
    protected $description = 'import valiable from yaml files';
13
    protected $valiable;
14
    protected $filesystem;
15
16 5
    public function __construct(Valiable $valiable,Filesystem $filesystem)
17
    {
18 5
        $this->valiable = $valiable;
19 5
        $this->filesystem = $filesystem;
20 5
        parent::__construct();
21 5
    }
22
    public function handle()
23
    {
24
        return $this->fire();
25
    }
26
27 4
    public function fire()
28
    {
29 4
        $path = storage_path('app/sonar_valiables');
30 4
        $files = $this->filesystem->allFiles($path);
31
32 4
        if ( is_array($files) === false || count($files) == 0 ) {
33 2
            throw new \Exception('ファイルが見つかりません。[' . $path . ']');
34
        }
35 2
        foreach ( $files as $rec ) {
36 2
            if ( preg_match("/\.yml$/",$rec->getPathname()) ) {
37 1
                $this->valiable->importYaml($this->filesystem->get($rec->getPathname()));
38
            }
39
        }
40 2
    }
41
42
}
43
44