Completed
Push — develop ( 73bd0a...ccb498 )
by Tom
05:04
created

TreeCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright © 2016 netz98 new media GmbH. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
7
namespace N98\Magento\Command\Developer\Console;
8
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Finder\Finder;
13
use Symfony\Component\Finder\SplFileInfo;
14
15
class TreeCommand extends AbstractGeneratorCommand
16
{
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('tree')
21
            ->addArgument('subpath', InputArgument::OPTIONAL, 'Show only subpath', '/')
22
            ->setDescription('Shows directory tree of current context');
23
    }
24
25
    /**
26
     * @param InputInterface $input
27
     * @param OutputInterface $output
28
     *
29
     * @return int|void
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $reader = $this->getCurrentModuleDirectoryReader();
34
35
        $finder = Finder::create();
36
        $finder
37
            ->files()
38
            ->in($reader->getAbsolutePath() . ltrim($input->getArgument('subpath'), '/'));
39
40
        foreach ($finder as $file) {
41
            /** @var $file SplFileInfo */
42
            $formattedRelativePath = $file->getRelativePath() == '' ? '' : $file->getRelativePath() . '/';
43
44
            $output->writeln(
45
                '<info>' . $formattedRelativePath . '</info>' . '<comment>' . $file->getFilename() . '</comment>'
46
            );
47
        }
48
    }
49
}
50