Completed
Push — master ( 9b25f2...d42705 )
by Tomáš
09:42 queued 07:08
created

FileSystemWriter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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\Renderable\File\File;
15
16
final class FileSystemWriter
17
{
18
    /**
19
     * @var string
20
     */
21
    private $sourceDirectory;
22
23
    /**
24
     * @var string
25
     */
26
    private $outputDirectory;
27
28 2
    public function __construct(string $sourceDirectory, string $outputDirectory)
29
    {
30 2
        $this->sourceDirectory = $sourceDirectory;
31 2
        $this->outputDirectory = $outputDirectory;
32 2
    }
33
34
    /**
35
     * @param SplFileInfo[] $files
36
     */
37 1
    public function copyStaticFiles(array $files)
38
    {
39 1
        foreach ($files as $file) {
40 1
            $relativeDestination = substr($file->getPathname(), strlen($this->sourceDirectory));
41 1
            $absoluteDestination = $this->outputDirectory.$relativeDestination;
42
43 1
            FileSystem::copy($file->getRealPath(), $absoluteDestination, true);
44
        }
45 1
    }
46
47
    /**
48
     * @param File[] $files
49
     */
50 1
    public function copyRenderableFiles(array $files)
51
    {
52 1
        foreach ($files as $file) {
53 1
            $absoluteDestination = $this->outputDirectory.DIRECTORY_SEPARATOR.$file->getOutputPath();
54 1
            FileSystem::createDir(dirname($absoluteDestination));
55 1
            file_put_contents($absoluteDestination, $file->getContent());
56
        }
57 1
    }
58
}
59