FindDirectoryCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
ccs 15
cts 15
cp 1
rs 9.4285
cc 1
eloc 16
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Class FindDirectoryCommand
4
 *
5
 * @author Mauro Moreno <[email protected]>
6
 */
7
namespace MauroMoreno\FindBundle\Command;
8
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * Class FindDirectoryCommand
17
 * @package MauroMoreno\FindBundle\Command
18
 */
19
class FindDirectoryCommand extends ContainerAwareCommand
20
{
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    protected function configure()
26
    {
27 3
        $this->setName('find:dir')
28 3
            ->setDescription('Find files that contains a pattern')
29 3
            ->addArgument(
30 3
                'pattern',
31 3
                InputArgument::REQUIRED,
32
                'Pattern is, by default, a basic regular expression.'
33 3
            )->addArgument(
34 3
                'directory',
35 3
                InputArgument::REQUIRED,
36
                'Directory path.'
37 3
            )->addOption(
38 3
                'extension',
39 3
                'e',
40 3
                InputOption::VALUE_NONE,
41
                'File extension.'
42 3
            );
43 3
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 3
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50 3
        $files = $this->getContainer()
51 3
            ->get('mauro_moreno_find.find_directory_service')
52 3
            ->setPattern($input->getArgument('pattern'))
53 3
            ->setDirectory($input->getArgument('directory'))
54 3
            ->setExtension($input->getOption('extension'))
55 3
            ->find();
56
57 3
        if ($files) {
58 2
            foreach($files as $file) {
59 2
                $output->writeln($file['filename']);
60 2
            }
61 2
        } else {
62 1
            $output->writeln('No results where found.');
63
        }
64 3
    }
65
66
}