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

ResultPrinter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A display() 0 20 2
A orderResults() 0 8 1
A formatSolutionFound() 0 14 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 "ResultPrinter.php" doesn't match the expected filename "resultprinter.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace JMGQ\AStar\Benchmark\Result;
4
5
use Symfony\Component\Console\Style\StyleInterface;
6
7
class ResultPrinter
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
8
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class ResultPrinter
Loading history...
9
    private $output;
0 ignored issues
show
Coding Style introduced by
Private member variable "output" 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 "output" must be prefixed with an underscore
Loading history...
10
11
    public function __construct(StyleInterface $output)
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...
12
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
13
        $this->output = $output;
14
    }
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...
15
16
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
17
     * @param AggregatedResult[] $results
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
18
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
19
    public function display(array $results)
20
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
21
        $tableRows = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
22
23
        $orderedResults = $this->orderResults($results);
24
25
        foreach ($orderedResults as $result) {
26
            $size = $result->getSize() . 'x' . $result->getSize();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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
Concat operator must not be surrounded by spaces
Loading history...
27
            $averageDuration = $result->getAverageDuration() . 'ms';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
28
            $minimumDuration = $result->getMinimumDuration() . 'ms';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
29
            $maximumDuration = $result->getMaximumDuration() . 'ms';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
30
            $solutionFound = $this->formatSolutionFound($result);
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...
31
32
            $tableRows[] = array($size, $averageDuration, $minimumDuration, $maximumDuration, $solutionFound);
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...
33
        }
34
35
        $tableHeaders = array('Size', 'Avg Duration', 'Min Duration', 'Max Duration', 'Solved?');
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...
36
37
        $this->output->table($tableHeaders, $tableRows);
38
    }
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 display()
Loading history...
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @param AggregatedResult[] $results
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
42
     * @return AggregatedResult[]
43
     */
44
    private function orderResults(array $results)
0 ignored issues
show
Coding Style introduced by
Private method name "ResultPrinter::orderResults" must be prefixed with an underscore
Loading history...
45
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
46
        usort($results, function ($a, $b) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
47
            return $a->getSize() > $b->getSize();
48
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
49
50
        return $results;
51
    }
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 orderResults()
Loading history...
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
     * @param AggregatedResult $result
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
55
     * @return string
56
     */
57
    private function formatSolutionFound($result)
0 ignored issues
show
Coding Style introduced by
Private method name "ResultPrinter::formatSolutionFound" must be prefixed with an underscore
Loading history...
introduced by
Type hint "AggregatedResult" missing for $result
Loading history...
58
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
59
        $allResultsAreSolved = $result->getNumberOfSolutions() === $result->getNumberOfTerrains();
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
60
        if ($allResultsAreSolved) {
61
            return 'Yes';
62
        }
63
64
        $allResultsAreUnsolved = $result->getNumberOfSolutions() === 0;
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
65
        if ($allResultsAreUnsolved) {
66
            return 'No';
67
        }
68
69
        return 'Sometimes';
70
    }
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 formatSolutionFound()
Loading history...
71
}
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...
72