Completed
Push — master ( 5b7a4b...70ecb8 )
by Elf
02:56
created

AlphabetGenerateCommand::generateRandomAlphabet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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