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

TemplateFolderProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 51
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B process() 0 24 2
A resolveTemplateOutputDir() 0 13 1
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