FileSystemWriter::copyStaticFiles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Output;
11
12
use Nette\Utils\FileSystem;
13
use SplFileInfo;
14
use Symplify\PHP7_Sculpin\Configuration\Configuration;
15
use Symplify\PHP7_Sculpin\Renderable\File\File;
16
17
final class FileSystemWriter
18
{
19
    /**
20
     * @var Configuration
21
     */
22
    private $configuration;
23
24 8
    public function __construct(Configuration $configuration)
25
    {
26 8
        $this->configuration = $configuration;
27 8
    }
28
29
    /**
30
     * @param SplFileInfo[] $files
31
     */
32 2
    public function copyStaticFiles(array $files)
33
    {
34 2
        foreach ($files as $file) {
35 1
            $relativeDestination = substr($file->getPathname(), strlen($this->configuration->getSourceDirectory()));
36 1
            $absoluteDestination = $this->configuration->getOutputDirectory() . $relativeDestination;
37
38 1
            FileSystem::copy($file->getRealPath(), $absoluteDestination, true);
39
        }
40 2
    }
41
42
    /**
43
     * @param File[] $files
44
     */
45 4
    public function copyRenderableFiles(array $files)
46
    {
47 4
        foreach ($files as $file) {
48 4
            $absoluteDestination = $this->configuration->getOutputDirectory()
49 4
                . DIRECTORY_SEPARATOR
50 4
                . $file->getOutputPath();
51
52 4
            FileSystem::createDir(dirname($absoluteDestination));
53 4
            file_put_contents($absoluteDestination, $file->getContent());
54
        }
55 4
    }
56
}
57