ListFontsCommand::execute()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 4
nc 6
nop 2
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
    /** {@inheritdoc} */
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('list:fonts')
19
            ->setDescription('List all the TTF fonts')
20
            ->addOption('fonts-path', null, InputOption::VALUE_OPTIONAL, 'Optional path to the fonts, if omitted, defaults to <base>/fonts')
21
        ;
22
    }
23
24
    /** {@inheritdoc} */
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $fontsPath = $input->getOption('fonts-path')
28
            ? realpath($input->getOption('fonts-path'))
29
            : constant('BASE_PATH') . '/fonts'
30
        ;
31
32
        $output->writeln(sprintf('Fonts found in "%s":', $fontsPath));
33
        $factory = FontsFactory::create($fontsPath);
34
        $fonts = $factory->getFonts();
35
36
        if (!count($fonts)) {
37
            $output->writeln('  No fonts found');
38
            return;
39
        }
40
41
        foreach ($fonts as $name) {
42
            $output->writeln(sprintf('  - %s', $name));
43
        }
44
    }
45
}
46