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

AlphabetGenerateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 42
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
A generateRandomAlphabet() 0 4 1
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