Failed Conditions
Push — master ( 28e23e...6697e2 )
by Yo
01:52
created

resolveTemplateOutputDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 3
crap 2
1
<?php
2
namespace Yoanm\DefaultPhpRepository\Processor;
3
4
use Symfony\Component\Finder\Finder;
5
use Yoanm\DefaultPhpRepository\Helper\PathHelper;
6
use Yoanm\DefaultPhpRepository\Registry\TemplateRegistry;
7
8
/**
9
 * Class TemplateFolderProcessor
10
 */
11
class TemplateFolderProcessor extends TemplateFileProcessor
12
{
13
    /**
14
     * @param string $templateFolderPath
15
     * @param string $templateOutputRootDir
16
     */
17
    public function process($templateFolderPath, $templateOutputRootDir = '.')
18
    {
19
        $finder = new Finder();
20
        $finder->files()->in($templateFolderPath);
21
22
        /** @var \SplFileInfo $file */
23
        foreach ($finder as $file) {
24
            $templateFilename = $file->getFilename();
25
            $templateFilePath = $file->getRealPath();
26
            $templateOutputFileDir = $this->resolveTemplateOutputDir(
27
                $templateFilename,
28
                $templateFilePath,
29
                $templateOutputRootDir
30
            );
31
32
            $templateOutputFilePath = sprintf(
33
                '%s%s',
34
                PathHelper::appendPathSeparator($templateOutputFileDir),
35
                $this->getHelper()->resolveOutputFilename($templateFilename)
36
            );
37
38
            $this->getHelper()->dumpTemplate($templateFilePath, $templateOutputFilePath);
39
        }
40
    }
41
42
    /**
43
     * @param string $templateFilename
44
     * @param string $templateFilePath
45
     * @param string $templateOutputRootDir
46
     * @return string
47
     */
48
    protected function resolveTemplateOutputDir(
49
        $templateFilename,
50
        $templateFilePath,
51
        $templateOutputRootDir
52
    ) {
53
        $resolved = sprintf(
54
            '%s%s',
55
            PathHelper::appendPathSeparator($templateOutputRootDir),
56
            str_replace([TemplateRegistry::getRootTemplateDir(), $templateFilename], '', $templateFilePath)
57
        );
58
59
        return $resolved;
60
    }
61
}
62