Completed
Push — master ( 70ecb8...2444e3 )
by Elf
02:14
created

AlphabetGenerateCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid\Console;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class AlphabetGenerateCommand extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'hashid:alphabet';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Generate a random alphabet for Hashid encoding';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return mixed
28
     */
29
    public function handle()
30 1
    {
31
        for ($i = 0; $i < $this->option('times'); $i++) {
32 1
            $this->comment(
33 1
                $this->generateRandomAlphabet($this->option('characters'))
34 1
            );
35
        }
36
    }
37 1
38
    /**
39
     * Generate random alphabet.
40
     *
41
     * @return string
42
     */
43
    protected function generateRandomAlphabet($characters)
44 1
    {
45
        return str_shuffle(count_chars($characters, 3));
46 1
    }
47
48
    /**
49
     * Get the console command options.
50
     *
51
     * @return array
52
     */
53
    protected function getOptions()
54
    {
55
        return [
56
            ['characters', 'c', InputOption::VALUE_OPTIONAL, 'Use custom characters', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'],
57
            ['times', 't', InputOption::VALUE_OPTIONAL, 'Times to generate', 1],
58
        ];
59
    }
60
}
61