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

ServiceAbstract   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 38
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A addGeneratedFileToIdeStack() 0 6 2
A getSplFile() 0 10 2
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