AbstractCommand::configure()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
namespace Guillermoandrae\Commands;
4
5
use ICanBoogie\Inflector;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
abstract class AbstractCommand extends Command
10
{
11
    /**
12
     * Configues the command. By default, uses the class name to derive the
13
     * command name.
14
     */
15 2
    protected function configure()
16
    {
17 2
        preg_match('/(\w+)Command/', get_class($this), $matches);
18 2
        if (isset($matches[1])) {
19 2
            $name = Inflector::get()->hyphenate($matches[1]);
20 2
            $this->setName($name);
21
        }
22 2
    }
23
24
    /**
25
     * Outputs the desired failure message.
26
     *
27
     * @param OutputInterface $output  The output instance.
28
     * @param string $message  The failure message.
29
     */
30 1
    final protected function fail(OutputInterface $output, string $message)
31
    {
32 1
        $output->writeln(
33 1
            sprintf('<fg=red;options=bold>An error occurred:</> <fg=red>%s</>', $message)
34
        );
35 1
        echo PHP_EOL;
36 1
    }
37
}
38