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

BenchmarkRunner::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
cc 3
nc 3
nop 3
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 "BenchmarkRunner.php" doesn't match the expected filename "benchmarkrunner.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\Example\Terrain\MyAStar;
7
use JMGQ\AStar\Example\Terrain\MyNode;
8
use Symfony\Component\Console\Helper\ProgressBar;
9
use Symfony\Component\Stopwatch\Stopwatch;
10
11
class BenchmarkRunner
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
12
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class BenchmarkRunner
Loading history...
13
    private $progressBar;
0 ignored issues
show
Coding Style introduced by
Private member variable "progressBar" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "progressBar" must be prefixed with an underscore
Loading history...
14
    private $terrainGenerator;
0 ignored issues
show
Coding Style introduced by
Private member variable "terrainGenerator" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "terrainGenerator" must be prefixed with an underscore
Loading history...
15
    private $stopwatch;
0 ignored issues
show
Coding Style introduced by
Private member variable "stopwatch" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "stopwatch" must be prefixed with an underscore
Loading history...
16
17
    public function __construct(ProgressBar $progressBar)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
18
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
19
        $this->progressBar = $progressBar;
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...
20
        $this->terrainGenerator = new TerrainGenerator();
21
        $this->stopwatch = new Stopwatch();
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...
22
    }
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 __construct()
Loading history...
23
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @param int[] $sizes
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
26
     * @param int $iterations
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
27
     * @param int | null $seed
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
28
     * @return Result[]
29
     */
30
    public function run(array $sizes, $iterations, $seed)
0 ignored issues
show
Coding Style introduced by
Type hint "int" missing for $iterations
Loading history...
31
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
32
        $results = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
33
34
        $steps = count($sizes) * $iterations;
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
35
        $this->progressBar->start($steps);
36
37
        foreach ($sizes as $size) {
38
            for ($i = 0; $i < $iterations; $i++) {
39
                $terrain = $this->terrainGenerator->generate($size, $size, $seed);
40
                $aStar = new MyAStar($terrain);
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...
41
42
                $start = new MyNode(0, 0);
43
                $goal = new MyNode($size - 1, $size - 1);
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...
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
44
45
                $this->stopwatch->start('benchmark');
46
47
                $solution = $aStar->run($start, $goal);
48
49
                $event = $this->stopwatch->stop('benchmark');
50
51
                $solutionFound = !empty($solution);
0 ignored issues
show
Coding Style introduced by
The value of a boolean operation must not be assigned to a variable
Loading history...
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
52
53
                $results[] = new Result($size, $event->getDuration(), $solutionFound);
54
55
                $this->stopwatch->reset();
56
57
                $this->progressBar->advance();
58
            }
0 ignored issues
show
Coding Style introduced by
End comment for long condition not found; expected "//end for"
Loading history...
59
        }
0 ignored issues
show
Coding Style introduced by
End comment for long condition not found; expected "//end foreach"
Loading history...
60
61
        $this->progressBar->finish();
62
63
        return $results;
64
    }
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 run()
Loading history...
65
}
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...
66