Passed
Push — master ( e86da3...7acf89 )
by BruceScrutinizer
09:02
created

populateOutputVarFromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
namespace NamespaceProtector\Showable;
3
4
use NamespaceProtector\Config as RootConfig;
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
class ConfigConsoleShowable implements ConfigShowableInterface {
8
9
    /** @var OutputInterface */
10
    private $console; 
11
12
    public function __construct(OutputInterface $outputInterface)
13
    {
14
        $this->console = $outputInterface;
15
    }
16
17
    public function show(RootConfig\Config $config): void
18
    {
19
        $prettyPrintPrivateEntries = $this->populateOutputVarFromArray($config->getPrivateEntries());
20
        $prettyPrintPublicEntries = $this->populateOutputVarFromArray($config->getPublicEntries());
21
22
        $output = 
23
            '' . PHP_EOL .
24
            '|Dump config:' . PHP_EOL .
25
            '|> Version: ' . $config->getVersion() . PHP_EOL .
26
            '|> Cache: ' . ($config->enabledCache() === true ? 'TRUE' : 'FALSE') . PHP_EOL .
27
            '|> Plotter: ' . $config->getPlotter() . PHP_EOL .
28
            '|> Path start: ' . $config->getStartPath()->get() . PHP_EOL .
29
            '|> Composer Json path: ' . $config->getPathComposerJson()->get() . PHP_EOL .
30
            '|> Mode: ' . $config->getMode() . PHP_EOL .
31
            '|> Private entries: ' . $prettyPrintPrivateEntries . PHP_EOL .
32
            '|' . PHP_EOL .
33
            '|> Public entries: ' . $prettyPrintPublicEntries . PHP_EOL .
34
            '';    
35
            
36
            echo $this->console->write($output);
37
    }
38
39
    /**
40
     * @param array<string> $entries
41
     */
42
    private function populateOutputVarFromArray(array $entries): string
43
    {
44
        $prettyPrintNamespaceToValidate = "\n";
45
        foreach ($entries as $namespace) {
46
            $prettyPrintNamespaceToValidate .= '|       >' . $namespace . \PHP_EOL;
47
        }
48
        return $prettyPrintNamespaceToValidate;
49
    }
50
51
}
52