Failed Conditions
Pull Request — release/0.2.0 (#12)
by Yo
02:25
created

ListTemplatesProcessor   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 80
ccs 0
cts 54
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 17 3
A displayTemplateInfo() 0 8 1
A displayFolderTitle() 0 8 1
A displayFileTitle() 0 8 1
A resolveTemplatePath() 0 12 3
1
<?php
2
namespace Yoanm\InitPhpRepository\Processor;
3
4
use Yoanm\InitPhpRepository\Helper\CommandHelper;
5
use Yoanm\InitPhpRepository\Model\FolderTemplate;
6
use Yoanm\InitPhpRepository\Model\Template;
7
use Yoanm\InitPhpRepository\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