Completed
Push — master ( cfafae...f1b5e0 )
by Elf
01:25
created

OptimusGenerateCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
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(
35 1
                $this->getTimes(),
36 1
                (int) $this->option('prime') ?: null
37 1
            )
38 1
        );
39 1
    }
40
41
    /**
42
     * Get "times" option value.
43
     *
44
     * @return int
45
     */
46 1
    protected function getTimes()
47
    {
48 1
        $times = (int) $this->option('times');
49
50 1
        return max(1, min($times, 100));
51
    }
52
53
    /**
54
     * Generate Optimus numbers.
55
     *
56
     * @param  int  $times
57
     * @param  int  $prime
58
     * @return array
59
     */
60 1
    protected function generateOptimusNumbers($times = 1, $prime = null)
61
    {
62 1
        $result = [];
63
64 1
        for ($i = 0; $i < $times; $i++) {
65 1
            $result[] = Energon::generate($prime);
66 1
        }
67
68 1
        return $result;
69
    }
70
71
    /**
72
     * Get the console command options.
73
     *
74
     * @return array
75
     */
76 2
    protected function getOptions()
77
    {
78
        return [
79 2
            ['prime', 'p', InputOption::VALUE_OPTIONAL, 'Generate with the given prime'],
80 2
            ['times', 't', InputOption::VALUE_OPTIONAL, 'Times to generate', 1],
81 2
        ];
82
    }
83
}
84