FindDirectoryCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 48
ccs 29
cts 29
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 19 1
A execute() 0 17 3
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
}