Passed
Push — master ( 0d0f52...07463e )
by Yuichi
02:21
created

ValiableImportCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B fire() 0 15 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 4
    public function __construct(Valiable $valiable,Filesystem $filesystem)
17
    {
18 4
        $this->valiable = $valiable;
19 4
        $this->filesystem = $filesystem;
20 4
        parent::__construct();
21 4
    }
22
23 3
    public function fire()
24
    {
25 3
        $path = storage_path('app/sonar_valiables');
26 3
        $files = $this->filesystem->allFiles($path);
27
28 3
        if ( is_array($files) && count($files) > 0 ) {
29 2
            foreach ( $this->filesystem->allFiles($path) as $rec ) {
30 2
                if ( preg_match("/\.yml$/",$rec->getPathname()) ) {
31 1
                    $this->valiable->importYaml($this->filesystem->get($rec->getPathname()));
32 1
                }
33 2
            }
34 2
        } else {
35 1
            throw new \Exception('ファイルが見つかりません。[' . $path . ']');
36
        }
37 2
    }
38
39
}
40
41