Test Failed
Pull Request — master (#9)
by Yo
03:11 queued 01:13
created

ListCommandProcessor::displayTemplateInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
namespace Yoanm\DefaultPhpRepository\Processor;
3
4
use Yoanm\DefaultPhpRepository\Model\FolderTemplate;
5
use Yoanm\DefaultPhpRepository\Model\Template;
6
use Yoanm\DefaultPhpRepository\Resolver\NamespaceResolver;
7
8
/**
9
 * Class ListCommandProcessor
10
 */
11
class ListCommandProcessor extends CommandProcessor
12
{
13
    public function process()
14
    {
15
        $currentType = null;
16
        foreach ($this->getTemplateList() as $template) {
17
            $this->displayHeader($template, $currentType);
18
19
            $currentType = $this->resolveCurrentType($template);
20
21
            if ($template instanceof FolderTemplate) {
22
                $this->displayFolderTitle($template);
23
                $this->displayTemplateInfo($template);
24
            } else {
25
                $this->displayFileTitle($template);
26
                $this->displayTemplateInfo($template);
27
            }
28
        }
29
    }
30
31
    /**
32
     * @param Template $template
33
     */
34
    protected function displayTemplateInfo(Template $template)
35
    {
36
        $this->display(sprintf(
37
            ' - %s/%s',
38
            $this->resolveTemplatePath($template),
39
            $template->getSource()
40
        ));
41
    }
42
43
    /**
44
     * @param Template $template
45
     */
46
    protected function displayFolderTitle(Template $template)
47
    {
48
        $this->display(
49
            sprintf('<comment>%s : </comment><info>Folder</info>', $template->getId()),
50
            2,
51
            false
52
        );
53
    }
54
55
    /**
56
     * @param Template $template
57
     */
58
    protected function displayFileTitle(Template $template)
59
    {
60
        $this->display(
61
            sprintf('<comment>%s : </comment><info>File</info>', $template->getId()),
62
            2,
63
            false
64
        );
65
    }
66
67
    protected function resolveTemplatePath(Template $template)
68
    {
69
        $basePath = 'templates';
70
        if (NamespaceResolver::SYMFONY_LIBRARY_NAMESPACE === $template->getNamespace()) {
71
            return sprintf('%s/override/library/symfony', $basePath);
72
        } elseif (NamespaceResolver::LIBRARY_NAMESPACE === $template->getNamespace()) {
73
            sprintf('%s/override/library/php', $basePath);
74
        }
75
76
        return sprintf('%s/base', $basePath);
77
    }
78
}
79