OffensiveWordsCommand::configure()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace PhpEarth\Stats\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class GenerateCommand
12
 */
13
class OffensiveWordsCommand extends Command
14
{
15
    private $offensiveWords = [];
16
17
    /**
18
     * Set offensive words from configuration file
19
     *
20
     * @param $offensiveWords
21
     */
22
    public function setOffensiveWords($offensiveWords)
23
    {
24
        $this->offensiveWords = $offensiveWords;
25
    }
26
27
    /**
28
     * Configures offensive words command for Console component.
29
     */
30
    protected function configure()
31
    {
32
        try {
33
            $this
34
                ->setName('offensive-words')
35
                ->setDescription('Manages offensive words')
36
            ;
37
        } catch (\Exception $e) {
38
            echo $e->getMessage();
39
        }
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $rows = [];
48
        foreach ($this->offensiveWords as $word) {
49
            $rows[] = [str_rot13($word[0]), $word[1], $word[0]];
50
        }
51
        $table = new Table($output);
52
        $table
53
            ->setHeaders(['String', 'Points', 'ROT13 Transformation'])
54
            ->setRows($rows)
55
        ;
56
        $table->render();
57
    }
58
}
59