Passed
Branch benchmark (b81757)
by Jose
10:16
created

BenchmarkCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "BenchmarkCommand.php" doesn't match the expected filename "benchmarkcommand.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace JMGQ\AStar\Benchmark;
4
5
use JMGQ\AStar\Benchmark\Result\Result;
6
use JMGQ\AStar\Benchmark\Result\ResultAggregator;
7
use JMGQ\AStar\Benchmark\Result\ResultPrinter;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\StyleInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
class BenchmarkCommand extends Command
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
16
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class BenchmarkCommand
Loading history...
17
    const SIZE_OPTION = 'size';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
18
    const ITERATIONS_OPTION = 'iterations';
19
    const SEED_OPTION = 'seed';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
20
21
    const SUCCESS_EXIT_CODE = 0;
22
    const ERROR_EXIT_CODE = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
23
24
    /**
25
     * {@inheritdoc}
26
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
27
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
29
        $name = 'benchmark';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
30
        $description = 'Runs a benchmark using the Terrain example';
31
        $help = 'This commands allows you to run a benchmark using the Terrain example';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
32
33
        $this->setName($name)
34
            ->setDescription($description)
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
35
            ->setHelp($help)
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
36
            ->addSizeOption()
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
37
            ->addIterationsOption()
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
38
            ->addSeedOption();
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
39
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end configure()
Loading history...
40
41
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $input should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $output should have a doc-comment as per coding-style.
Loading history...
42
     * {@inheritdoc}
43
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
46
        $styledOutput = new SymfonyStyle($input, $output);
47
48
        $inputValidator = new InputValidator($styledOutput);
49
        $hasValidInput = $inputValidator->validate($input);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
50
51
        if (!$hasValidInput) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
52
            return self::ERROR_EXIT_CODE;
53
        }
54
55
        $sizes = $input->getOption(self::SIZE_OPTION);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56
        $iterations = $input->getOption(self::ITERATIONS_OPTION);
57
        $seed = $input->getOption(self::SEED_OPTION);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
58
59
        $progressBar = $styledOutput->createProgressBar();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
60
        $benchmarkRunner = new BenchmarkRunner($progressBar);
61
62
        $results = $benchmarkRunner->run($sizes, $iterations, $seed);
63
64
        $this->printResults($results, $styledOutput);
65
66
        return self::SUCCESS_EXIT_CODE;
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end execute()
Loading history...
68
69
    private function addSizeOption()
0 ignored issues
show
Coding Style introduced by
Private method name "BenchmarkCommand::addSizeOption" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
70
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
71
        $description = 'Number of rows and columns of the terrain';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
72
        $defaultValue = array(5, 10, 15, 20, 25);
0 ignored issues
show
Coding Style introduced by
Arrays with multiple values should not be declared on a single line.
Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
73
74
        $this->addOption(
75
            self::SIZE_OPTION,
76
            's',
77
            InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
78
            $description,
79
            $defaultValue
80
        );
81
82
        return $this;
83
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end addSizeOption()
Loading history...
84
85
    private function addIterationsOption()
0 ignored issues
show
Coding Style introduced by
Private method name "BenchmarkCommand::addIterationsOption" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
86
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
87
        $description = 'Number of times the algorithm will run against each terrain';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
88
        $defaultValue = 10;
89
90
        $this->addOption(self::ITERATIONS_OPTION, 'i', InputOption::VALUE_REQUIRED, $description, $defaultValue);
91
92
        return $this;
93
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end addIterationsOption()
Loading history...
94
95
    private function addSeedOption()
0 ignored issues
show
Coding Style introduced by
Private method name "BenchmarkCommand::addSeedOption" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
96
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
97
        $description = 'Integer used to generate random costs. Set the same value in order to replicate an execution';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
98
        $defaultValue = null;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
99
100
        $this->addOption(self::SEED_OPTION, 'e', InputOption::VALUE_REQUIRED, $description, $defaultValue);
101
102
        return $this;
103
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end addSeedOption()
Loading history...
104
105
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
106
     * @param Result[] $results
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
107
     * @param StyleInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
108
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
109
    private function printResults(array $results, StyleInterface $output)
0 ignored issues
show
Coding Style introduced by
Private method name "BenchmarkCommand::printResults" must be prefixed with an underscore
Loading history...
110
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
111
        $output->newLine();
112
113
        $resultAggregator = new ResultAggregator();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
114
        $aggregatedResults = $resultAggregator->process($results);
115
116
        $resultPrinter = new ResultPrinter($output);
117
        $resultPrinter->display($aggregatedResults);
118
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end printResults()
Loading history...
119
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
120