ListFontsCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 20 4
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