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

ValiableImportCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
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