Passed
Pull Request — master (#2)
by Thomas
03:05
created

ServiceAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 35
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addLatestFileToIdeStack() 0 4 1
A latestCreatedFileIn() 0 8 1
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Contracts;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Symfony\Component\Finder\SplFileInfo;
7
use Webfactor\Laravel\Generators\Commands\MakeEntity;
8
9
abstract class ServiceAbstract
10
{
11
    protected $command;
12
13
    protected $filesystem;
14
15
    protected $relativeToBasePath;
16
17
    public function __construct(MakeEntity $command)
18
    {
19
        $this->command = $command;
20
        $this->filesystem = new Filesystem();
21
    }
22
23
    protected function addLatestFileToIdeStack()
24
    {
25
        $this->command->addFile($this->latestCreatedFileIn(base_path($this->relativeToBasePath)));
26
    }
27
28
    /**
29
     * Returns the latest created File in given Path to use it for $filesToBeOpened stack
30
     *
31
     * @param string $path
32
     *
33
     * @return SplFileInfo
34
     */
35
    protected function latestCreatedFileIn(string $path): SplFileInfo
36
    {
37
        $sortedByMTime = array_sort($this->filesystem->files($path), function ($file) {
38
            return $file->getMTime();
39
        });
40
41
        return end($sortedByMTime);
42
    }
43
}
44