Passed
Pull Request — master (#12)
by Thomas
02:09
created

ServiceAbstract::addGeneratedFileToIdeStack()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Contracts;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Webfactor\Laravel\Generators\Commands\MakeEntity;
7
8
abstract class ServiceAbstract
9
{
10
    protected $command;
11
12
    protected $key;
13
14
    protected $naming;
15
16
    protected $filesystem;
17
18
    public function __construct(MakeEntity $command)
19
    {
20
        $this->command = $command;
21
        $this->filesystem = new Filesystem();
22
23
        if ($this->key) {
24
            $this->naming = $this->command->naming[$this->key];
25
        }
26
    }
27
28
    protected function addGeneratedFileToIdeStack()
29
    {
30
        if ($file = $this->command->naming[$this->key]->getFile()) {
31
            $this->command->addFile($this->getSplFile($file));
32
        }
33
    }
34
35
    private function getSplFile(string $pathToFile): \SplFileInfo
36
    {
37
        $splFile = new \SplFileInfo($pathToFile);
38
39
        if ($splFile->isFile()) {
40
            return $splFile;
41
        }
42
43
        return null;
44
    }
45
}
46