Passed
Push — master ( 6e26c0...38e037 )
by Dan
02:58
created

ListFontsCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace SixtyNine\Cloud\Command;
4
5
use SixtyNine\Cloud\Factory\FontsFactory;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class ListFontsCommand extends Command
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('list:fonts')
18
            ->setDescription('List all the TTF fonts')
19
            ->addOption('fonts-path', null, InputOption::VALUE_OPTIONAL, 'Optional path to the fonts, if omitted, defaults to <base>/fonts')
20
        ;
21
    }
22
23
    protected function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $fontsPath = $input->getOption('fonts-path')
26
            ? realpath($input->getOption('fonts-path'))
27
            : constant('BASE_PATH') . '/fonts'
28
        ;
29
30
        $output->writeln(sprintf('Fonts found in "%s":', $fontsPath));
31
        $factory = FontsFactory::create($fontsPath);
32
        $fonts = $factory->getFonts();
33
34
        if (!count($fonts)) {
35
            $output->writeln('  No fonts found');
36
            return;
37
        }
38
39
        foreach ($fonts as $name) {
40
            $output->writeln(sprintf('  - %s', $name));
41
        }
42
    }
43
}
44