ConsoleAdapter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 1
cbo 4
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 2
1
<?php
2
3
namespace Crummy\Phlack\Bridge\Symfony\Console;
4
5
use Crummy\Phlack\Bot\Mainframe\Adapter\AbstractAdapter;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class ConsoleAdapter extends AbstractAdapter
10
{
11 1
    public function execute(InputInterface $input, OutputInterface $output)
12
    {
13 1
        $in = $input->getArgument('command');
14 1
        $text = is_array($in) ? implode(' ', $in) : $in;
15 1
        $command = $this->converter->convert($text);
0 ignored issues
show
Bug introduced by
The method convert does only exist in Crummy\Phlack\WebHook\Converter\StringConverter, but not in Crummy\Phlack\WebHook\Converter\ConverterInterface.

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...
16 1
        $result = (string) $this->mainframe->execute($command)['output']->get('text');
17 1
        $output->writeln($result);
18 1
    }
19
}
20