Completed
Push — master ( c0e116...21c620 )
by Konstantinos
04:46
created

AnalyzeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
B execute() 0 34 2
1
<?php
2
3
namespace IVCalculator\Console\Commands;
4
5
use IVCalculator\IVCalculator;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Helper\Table;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class AnalyzeCommand extends Command
13
{
14
    protected function configure()
15
    {
16
        $this->setName('analyze')
17
            ->setDescription('Analyzes a pokemon.');
18
19
        $this->addArgument('nameOrId', InputArgument::REQUIRED, 'The Pokemon\'s name or ID')
20
            ->addArgument('CP', InputArgument::REQUIRED)
21
            ->addArgument('HP', InputArgument::REQUIRED)
22
            ->addArgument('dustCost', InputArgument::REQUIRED, 'Stardust needed for power up')
23
            ->addArgument('neverUpgraded', InputArgument::OPTIONAL, ' Was powered up before?');
24
    }
25
26
    protected function execute(InputInterface $input, OutputInterface $output)
27
    {
28
        $results = (new IVCalculator())->evaluate(
29
            $input->getArgument('nameOrId'),
30
            (int) $input->getArgument('CP'),
31
            (int) $input->getArgument('HP'),
32
            (int) $input->getArgument('dustCost'),
33
            $input->getArgument('neverUpgraded') == 'true' ? true : false
34
        );
35
36
        // Title
37
        $output->writeln('=========================');
38
        $output->writeln(
39
            sprintf(
40
                "%s (%.0f%%)",
41
                $results->get('name'),
42
                $results->get('perfection')->get('average') * 100
43
            )
44
        );
45
        $output->writeln("=========================\n");
46
47
        // IVs
48
        (new Table($output))
49
            ->setHeaders(array('Perfection', 'Attack IV', 'Defense IV', 'Stamina IV', 'Level'))
50
            ->setRows($results->get('ivs')->map(function($iv) {
51
                return [
52
                    sprintf('%.0f%%', $iv->perfection * 100),
53
                    $iv->attackIV,
54
                    $iv->defenseIV,
55
                    $iv->staminaIV,
56
                    $iv->level
57
                ];
58
            })->toArray())->render();
59
    }
60
}
61