Completed
Push — master ( 9f5c60...27ad1b )
by Elf
02:57
created

OptimusGenerateCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid\Console;
4
5
use Illuminate\Console\Command;
6
use Jenssegers\Optimus\Energon;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class OptimusGenerateCommand extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'hashid:optimus';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Generate Optimus numbers';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30 1
    public function handle()
31
    {
32 1
        $this->table(
33 1
            ['prime', 'inverse', 'random'],
34 1
            $this->generateOptimusNumbers($this->getTimes())
35 1
        );
36 1
    }
37
38
    /**
39
     * Get "times" option value.
40
     *
41
     * @return int
42
     */
43 1
    protected function getTimes()
44
    {
45 1
        $times = (int) $this->option('times');
46
47 1
        return max(1, min($times, 100));
48
    }
49
50
    /**
51
     * Generate Optimus numbers.
52
     *
53
     * @param  int  $times
54
     * @return array
55
     */
56 1
    protected function generateOptimusNumbers($times = 1)
57
    {
58 1
        $result = [];
59
60 1
        for ($i = 0; $i < $times; $i++) {
61 1
            $result[] = Energon::generate();
62 1
        }
63
64 1
        return $result;
65
    }
66
67
    /**
68
     * Get the console command options.
69
     *
70
     * @return array
71
     */
72 2
    protected function getOptions()
73
    {
74
        return [
75 2
            ['times', 't', InputOption::VALUE_OPTIONAL, 'Times to generate', 1],
76 2
        ];
77
    }
78
}
79