Test Failed
Pull Request — master (#9)
by Yo
02:00
created

ListCommandProcessor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 68
ccs 0
cts 49
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 3
A displayTemplateInfo() 0 8 1
A displayFolderTitle() 0 8 1
A displayFileTitle() 0 8 1
A resolveTemplatePath() 0 11 3
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