ListDumpsCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
crap 6
1
<?php
2
namespace Tivnet\WPDB\Command;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
use Tivnet\Console\Utils;
10
use Tivnet\WPDB\Config;
11
use Tivnet\WPDB\I;
12
13
/**
14
 * Class ListDumpsCommand
15
 * @package Tivnet\WPDB\Command
16
 */
17
class ListDumpsCommand extends Command {
18
19
	/**
20
	 * Configuration
21
	 *
22
	 * @return void
23
	 */
24
	protected function configure() {
25
		$this->setName( 'list-dumps' )
26
		     ->setDescription( 'List dump files' )
27
		     ->setHelp( /** @lang text */
28
			     'The <info>list-dumps</info> shows the dump files in the `data` folder' );
29
	}
30
31
	/**
32
	 * Executes the command
33
	 *
34
	 * @param InputInterface  $input
35
	 * @param OutputInterface $output
36
	 *
37
	 * @return null|int
38
	 */
39
	protected function execute( InputInterface $input, OutputInterface $output ) {
40
41
		$iterator = new \RegexIterator(
42
			new \RecursiveIteratorIterator(
43
				new \RecursiveDirectoryIterator( I::$cfg->get( 'dir_dump' ) )
44
			),
45
			'/.+\.' . I::$cfg->get( 'dump_ext' ) . '.*/',
46
			\RecursiveRegexIterator::GET_MATCH
47
		);
48
49
		foreach ( $iterator as $path ) {
50
			$output->writeln( Utils::ls_l( $path[0] ) );
51
		}
52
53
		return null;
54
	}
55
}
56