CalculateCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 9
dl 0
loc 79
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 38 1
B execute() 0 37 1
1
<?php
2
3
/*
4
 * (c) Jérémy Marodon <[email protected]>
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Th3Mouk\PokemonGoIVCalculator\Commands;
10
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Helper\Table;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Th3Mouk\PokemonGoIVCalculator\Calculator\Calculator;
17
use Th3Mouk\PokemonGoIVCalculator\Entities\IvCombinaison;
18
19
class CalculateCommand extends Command
20
{
21
    protected function configure()
22
    {
23
        $this
24
            ->setName('calculate')
25
            ->setDescription('Calculate IV combinaisons of a Pokemon');
26
27
        $this
28
            ->addArgument('name', InputArgument::REQUIRED, 'Pokemon\'s name')
29
            ->addArgument('cp', InputArgument::REQUIRED)
30
            ->addArgument('hp', InputArgument::REQUIRED)
31
            ->addArgument(
32
                'dusts',
33
                InputArgument::REQUIRED,
34
                'Stardust needed for power up'
35
            )
36
            ->addArgument(
37
                'global',
38
                InputArgument::REQUIRED,
39
                '1/2/3/4 for globalement evalutation'
40
            )
41
            ->addArgument(
42
                'max-stats',
43
                InputArgument::REQUIRED,
44
                '1/2/3/4 for best stat evalutation'
45
            )
46
            ->addArgument(
47
                'bests',
48
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
49
                'atk def hp separated with spaces'
50
            )
51
            ->addOption(
52
                'upgraded',
53
                'up',
54
                InputArgument::OPTIONAL,
55
                'Is the Pokemon was powered up?',
56
                false
57
            );
58
    }
59
60
    protected function execute(InputInterface $input, OutputInterface $output)
61
    {
62
        $pokemon = (new Calculator())->calculate(
63
            $input->getArgument('name'),
64
            (int) $input->getArgument('cp'),
65
            (int) $input->getArgument('hp'),
66
            (int) $input->getArgument('dusts'),
67
            (int) $input->getArgument('global'),
68
            (int) $input->getArgument('max-stats'),
69
            $input->getArgument('bests'),
70
            (bool) $input->getOption('upgraded')
71
        );
72
73
        $output->writeln('====================================');
74
        $output->writeln(
75
            sprintf(
76
                "%s (%.1f%%)   %.1f%% / %.1f%%",
77
                ucfirst($pokemon->getName()),
78
                $pokemon->getAveragePerfection(),
79
                $pokemon->getMinimumCombinaison()->getPerfection(),
80
                $pokemon->getMaximumCombinaison()->getPerfection()
81
            )
82
        );
83
        $output->writeln("====================================");
84
85
        (new Table($output))
86
            ->setHeaders(['Level', 'Attack IV', 'Defense IV', 'Stamina IV', 'Perfection'])
87
            ->setRows($pokemon->getIvCombinaisons()->map(function (IvCombinaison $combinaison) {
88
                return [
89
                    $combinaison->getLevel()->getLevel(),
90
                    $combinaison->getAttack(),
91
                    $combinaison->getDefense(),
92
                    $combinaison->getStamina(),
93
                    sprintf('%.1f%%', $combinaison->getPerfection()),
94
                ];
95
            })->toArray())->render();
96
    }
97
}
98