FormatterCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 9.8333
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 12
1
<?php
2
namespace gossi\formatter\commands;
3
4
use gossi\formatter\Formatter;
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\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class FormatterCommand extends Command {
12
13
	/* (non-PHPdoc)
14
	 * @see \Symfony\Component\Console\Command\Command::configure()
15
	 */
16
	protected function configure() {
17
		$this
18
			->setName('format')
19
			->setDescription('Beautify PHP Code')
20
			->addArgument(
21
				'input',
22
				InputArgument::REQUIRED,
23
				'The input'
24
			)
25
// 			->addArgument(
26
// 				'output',
27
// 				InputArgument::OPTIONAL,
28
// 				'The output'
29
// 			)
30
			->addOption(
31
				'profile',
32
				null,
33
				InputOption::VALUE_OPTIONAL,
34
				'The profile with the formatting options'
35
			)
36
		;
37
	}
38
39
	protected function execute(InputInterface $in, OutputInterface $output) {
40
		$in = $in->getArgument('input');
41
// 		$out = $in->getArgument('output');
42
43
		$code = file_exists($in) ? file_get_contents($in) : null;
44
45
		if ($code !== null) {
46
			$formatter = new Formatter();
47
			$beauty = $formatter->format($code);
48
49
			echo $output->writeln($beauty);
50
		}
51
	}
52
53
}
54