Completed
Push — 42-formatter ( cff7a4 )
by Nicolas
32:10 queued 28:41
created

Command::printHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Karma;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Karma\Logging\OutputInterfaceAdapter;
9
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
10
11
class Command extends \Symfony\Component\Console\Command\Command
12
{
13
    use \Karma\Logging\OutputAware;
14
    
15
    protected
16
        $app;
17
    
18
    public function __construct(Application $app)
19
    {
20
        parent::__construct();
21
        
22
        $this->app = $app;
23
    }
24
    
25
    protected function configure()
26
    {
27
        $this->addOption('cache', null, InputOption::VALUE_NONE, 'Cache the dist files list');
28
    }
29
    
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $this->configureOutputInterface($output);
33
        $this->printHeader();
34
35
        $profile = $this->app['profile'];
36
        
37
        $confDir = Application::DEFAULT_CONF_DIRECTORY;
38
        if($profile->hasConfigurationDirectory())
39
        {
40
            $confDir = $profile->getConfigurationDirectory();
41
        }
42
        
43
        $masterFile = Application::DEFAULT_MASTER_FILE;
44
        if($profile->hasMasterFilename())
45
        {
46
            $masterFile = $profile->getMasterFilename();
47
        }
48
        
49
        $suffix = Application::DEFAULT_DISTFILE_SUFFIX;
50
        if($profile->hasTemplatesSuffix())
51
        {
52
            $suffix = $profile->getTemplatesSuffix();
53
        }
54
        
55
        $this->app['configuration.path']       = $confDir;
56
        $this->app['configuration.masterFile'] = $masterFile;
57
        $this->app['distFiles.suffix'] = $suffix;
58
        
59
        $this->app['logger'] = new OutputInterfaceAdapter($output);
60
        
61
        if($input->getOption('cache'))
62
        {
63
            $this->enableFinderCache();
64
        }
65
    }
66
    
67
    private function configureOutputInterface(OutputInterface $output)
68
    {
69
        $style = new OutputFormatterStyle('cyan', null, array('bold'));
70
        $output->getFormatter()->setStyle('important', $style);
71
        
72
        $this->setOutput($output);
73
    }
74
    
75
    private function enableFinderCache()
76
    {
77
        $this->app['sources.fileSystem.finder'] = $this->app['sources.fileSystem.cached'];
78
    }
79
    
80
    protected function formatValue($value)
81
    {
82
        if($value === false)
83
        {
84
            $value = 'false';
85
        }
86
        elseif($value === true)
87
        {
88
            $value = 'true';
89
        }
90
        elseif($value === null)
91
        {
92
            $value = '<fg=white;options=bold>NULL</fg=white;options=bold>';
93
        }
94
        elseif($value === Configuration::NOT_FOUND)
95
        {
96
            $value = '<error>NOT FOUND</error>';
97
        }
98
    
99
        return $value;
100
    }
101
    
102
    private function printHeader()
103
    {
104
        $this->output->writeln(sprintf(
105
           '<comment>%s</comment>',
106
           $this->getLogo()
107
        ));
108
    }
109
    
110
    private function getLogo()
111
    {
112
        $logo = <<<ASCIIART
113
  _  __                          
114
 | |/ /__ _ _ __ _ __ ___   __ _ 
115
 | ' // _` | '__| '_ ` _ \ / _` |
116
 | . \ (_| | |  | | | | | | (_| |
117
 |_|\_\__,_|_|  |_| |_| |_|\__,_|
118
119
ASCIIART;
120
        
121
        return sprintf(
122
            "%s\n %s %s -\n",
123
            $logo,
124
            str_pad('', 30 - strlen(Application::VERSION), '-'),
125
            Application::VERSION
126
        );
127
        
128
    }
129
    
130
}