ValiableImportCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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