Passed
Push — develop ( 667b67...a1f6a6 )
by Brent
03:21
created

CopyStaticFiles   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 16 4
A copyStaticFile() 0 10 2
1
<?php
2
3
namespace Stitcher\Task;
4
5
use Stitcher\File;
6
use Stitcher\Task;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
class CopyStaticFiles implements Task
10
{
11
    private $fs;
12
    private $staticFiles;
13
    private $cacheStaticFiles;
14
    private $publicDirectory;
15
16 4
    public function __construct(string $publicDirectory, array $staticFiles, bool $cacheStaticFiles)
17
    {
18 4
        $this->fs = new Filesystem();
19 4
        $this->publicDirectory = $publicDirectory;
20 4
        $this->staticFiles = $staticFiles;
21 4
        $this->cacheStaticFiles = $cacheStaticFiles;
22 4
    }
23
24 2
    public function execute(): void
25
    {
26 2
        foreach ($this->staticFiles as $staticFile) {
27 2
            $staticFile = trim($staticFile, '/');
28
29 2
            $publicPath = File::path("{$this->publicDirectory}/{$staticFile}");
30
31 2
            if ($this->cacheStaticFiles && $this->fs->exists($publicPath)) {
32
                continue;
33
            }
34
35 2
            $sourcePath = File::path($staticFile);
36
37 2
            $this->copyStaticFile($sourcePath, $publicPath);
38
        }
39 2
    }
40
41 2
    private function copyStaticFile(string $sourcePath, string $publicPath): void
42
    {
43 2
        if (is_dir($sourcePath)) {
44 2
            $this->fs->mirror($sourcePath, $publicPath);
45
46 2
            return;
47
        }
48
49 2
        $this->fs->copy($sourcePath, $publicPath);
50 2
    }
51
}
52