Completed
Push — master ( 997958...c1a544 )
by Adam
02:44
created

Console   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 4
dl 0
loc 54
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 4 1
A output() 0 8 3
A loopRows() 0 7 3
A addRow() 0 9 2
1
<?php
2
3
namespace BestServedCold\Benchmark\Output;
4
5
use BestServedCold\Benchmark\Benchmark;
6
use BestServedCold\Benchmark\Dependency;
7
use BestServedCold\PhalueObjects\Metric;
8
use Symfony\Component\Console\Helper\Table;
9
use Symfony\Component\Console\Helper\TableSeparator;
10
11
/**
12
 * Class Console
13
 *
14
 * @package BestServedCold\Benchmark\Output
15
 */
16
class Console extends AbstractOutput implements OutputInterface
17
{
18
    /**
19
     * @codeCoverageIgnore impossible to test as writes to php://stdout
20
     */
21
    public function render()
22
    {
23
        $this->output->render();
0 ignored issues
show
Bug introduced by
The method render does only exist in BestServedCold\Benchmark\Output\Html, but not in Symfony\Component\Console\Output\OutputInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
24
    }
25
    
26
    /**
27
     * @param  Benchmark      $benchmark
28
     * @param  Table          $table
29
     * @param  TableSeparator $tableSeparator
30
     * @return string
31
     */
32 1
    public static function output(Benchmark $benchmark, Table $table = null, TableSeparator $tableSeparator = null)
33
    {
34 1
        $table          = $table          ?: Dependency::symfonyTable();
35 1
        $tableSeparator = $tableSeparator ?: Dependency::symfonyTableSeparator();
36 1
        $table->setHeaders(self::$headers);
37 1
        self::loopRows($table, $tableSeparator, $benchmark->getMarkers());
38 1
        return new static($table);
39
    }
40
41
    /**
42
     * @param Table          $table
43
     * @param TableSeparator $tableSeparator
44
     * @param array          $rows
45
     */
46 1
    protected static function loopRows(Table $table, TableSeparator $tableSeparator, array $rows)
47
    {
48 1
        foreach($rows as $name => $row) {
49 1
            $table = static::addRow($table, $row, $name);
50 1
            $row === end($rows) ?: $table->addRow($tableSeparator);
51 1
        }
52 1
    }
53
54
    /**
55
     * @param  Table       $table
56
     * @param  array       $metrics
57
     * @param  bool|string $name
58
     * @return Table
59
     */
60 1
    protected static function addRow(Table $table, array $metrics, $name)
61
    {
62
        /** @var Metric $metric */
63 1
        foreach ($metrics as $metric) {
64 1
            $table->addRow(parent::populateRow($metric, $name));
0 ignored issues
show
Bug introduced by
It seems like $name defined by parameter $name on line 60 can also be of type boolean; however, BestServedCold\Benchmark...ctOutput::populateRow() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (populateRow() instead of addRow()). Are you sure this is correct? If so, you might want to change this to $this->populateRow().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
65 1
        }
66
67 1
        return $table;
68
    }
69
}
70