Failed Conditions
Push — master ( c3b9f6...b14904 )
by Yo
02:03
created

ListTemplatesProcessor::displayFileTitle()   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\Helper\CommandHelper;
5
use Yoanm\DefaultPhpRepository\Model\FolderTemplate;
6
use Yoanm\DefaultPhpRepository\Model\Template;
7
use Yoanm\DefaultPhpRepository\Resolver\NamespaceResolver;
8
9
/**
10
 * Class ListTemplatesProcessor
11
 */
12
class ListTemplatesProcessor
13
{
14
    /** @var CommandHelper */
15
    private $helper;
16
17
    /**
18
     * @param CommandHelper $helper
19
     */
20
    public function __construct(CommandHelper $helper)
21
    {
22
        $this->helper = $helper;
23
    }
24
25
    public function process()
26
    {
27
        $currentType = null;
28
        foreach ($this->helper->getTemplateList() as $template) {
29
            $this->helper->displayHeader($template, $currentType);
30
31
            $currentType = $this->helper->resolveCurrentType($template);
32
33
            if ($template instanceof FolderTemplate) {
34
                $this->displayFolderTitle($template);
35
                $this->displayTemplateInfo($template);
36
            } else {
37
                $this->displayFileTitle($template);
38
                $this->displayTemplateInfo($template);
39
            }
40
        }
41
    }
42
43
    /**
44
     * @param Template $template
45
     */
46
    protected function displayTemplateInfo(Template $template)
47
    {
48
        $this->helper->display(sprintf(
49
            ' - %s/%s',
50
            $this->resolveTemplatePath($template),
51
            $template->getSource()
52
        ));
53
    }
54
55
    /**
56
     * @param Template $template
57
     */
58
    protected function displayFolderTitle(Template $template)
59
    {
60
        $this->helper->display(
61
            sprintf('<comment>%s : </comment><info>Folder</info>', $template->getId()),
62
            2,
63
            false
64
        );
65
    }
66
67
    /**
68
     * @param Template $template
69
     */
70
    protected function displayFileTitle(Template $template)
71
    {
72
        $this->helper->display(
73
            sprintf('<comment>%s : </comment><info>File</info>', $template->getId()),
74
            2,
75
            false
76
        );
77
    }
78
79
    protected function resolveTemplatePath(Template $template)
80
    {
81
        $basePath = 'templates';
82
        $path = sprintf('%s/base', $basePath);
83
        if (NamespaceResolver::SYMFONY_LIBRARY_NAMESPACE === $template->getNamespace()) {
84
            $path = sprintf('%s/override/library/symfony', $basePath);
85
        } elseif (NamespaceResolver::LIBRARY_NAMESPACE === $template->getNamespace()) {
86
            $path = sprintf('%s/override/library/php', $basePath);
87
        }
88
89
        return $path;
90
    }
91
}
92