SymfonyOptimize::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Dumkaaa\BxOptimize\Cli;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class SymfonyOptimize extends Command
11
{
12
    protected function configure()
13
    {
14
        $this
15
            ->setName('bxoptimize:optimize')
16
            ->setDescription('Set up optimization')
17
            ->addArgument(
18
                'path',
19
                InputArgument::REQUIRED,
20
                'Path to find files'
21
            )
22
            ->addArgument(
23
                'handlers',
24
                InputArgument::IS_ARRAY,
25
                'Array of optimizators to set up'
26
            );
27
    }
28
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $path = $input->getArgument('path');
32
        $handlers = $input->getArgument('handlers');
33
34
        try {
35
            $finder = new \Dumkaaa\BxOptimize\Finder\FilesFinder($path);
36
            $handler = new \Dumkaaa\BxOptimize\Handler\HandlerProcessor($handlers);
37
38
            $optimizer = new \Dumkaaa\BxOptimize\Optimizer($finder, $handler);
39
            $optimizer->optimize();
40
41
            $output->writeln('<info>BxOptimization set up.</info>');
42
        } catch (\Exception $e) {
43
            $output->writeln('<error>' . get_class($e) . ': ' . $e->getMessage() . '</error>');
44
        }
45
    }
46
}
47