SuiteControllerDecorator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 4 1
A execute() 0 18 3
1
<?php
2
3
namespace Bex\Behat\ChooseTestsExtension\Decorator;
4
5
use Behat\Testwork\Cli\Controller;
6
use Behat\Testwork\EventDispatcher\TestworkEventDispatcherSymfonyLegacy;
7
use Bex\Behat\ChooseTestsExtension\Event\AfterAvailableSuitesRegistered;
8
use Bex\Behat\ChooseTestsExtension\Event\AvailableSuitesRegistered;
9
use Bex\Behat\ChooseTestsExtension\Event\BeforeAvailableSuitesRegistered;
10
use Symfony\Component\Console\Command\Command as SymfonyCommand;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14
15
class SuiteControllerDecorator implements Controller
16
{
17
    /**
18
     * @var Controller
19
     */
20
    private $suiteContoller;
21
    
22
    /**
23
     * @var EventDispatcherInterface
24
     */
25
    private $eventDispatcher;
26
    
27
    /**
28
     * @param Controller               $suiteContoller
29
     * @param EventDispatcherInterface $eventDispatcher
30
     */
31
    public function __construct(Controller $suiteContoller, EventDispatcherInterface $eventDispatcher)
32
    {
33
        $this->suiteContoller = $suiteContoller;
34
        $this->eventDispatcher = $eventDispatcher;
35
    }
36
37
    /**
38
     * Configures command to be executable by the controller.
39
     *
40
     * @param SymfonyCommand $command
41
     */
42
    public function configure(SymfonyCommand $command)
43
    {
44
        return $this->suiteContoller->configure($command);
45
    }
46
47
    /**
48
     * Executes controller.
49
     *
50
     * @param InputInterface  $input
51
     * @param OutputInterface $output
52
     *
53
     * @return null|integer
54
     */
55
    public function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        if ($this->eventDispatcher instanceof TestworkEventDispatcherSymfonyLegacy) {
58
            $this->eventDispatcher->dispatch(AvailableSuitesRegistered::BEFORE, new BeforeAvailableSuitesRegistered());
59
        } else {
60
            $this->eventDispatcher->dispatch(new BeforeAvailableSuitesRegistered(), AvailableSuitesRegistered::BEFORE);    
0 ignored issues
show
Documentation introduced by
new \Bex\Behat\ChooseTes...lableSuitesRegistered() is of type object<Bex\Behat\ChooseT...ilableSuitesRegistered>, but the function expects a object<Symfony\Contracts\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
        }
62
        
63
        $result = $this->suiteContoller->execute($input, $output);
64
65
        if ($this->eventDispatcher instanceof TestworkEventDispatcherSymfonyLegacy) {
66
            $this->eventDispatcher->dispatch(AvailableSuitesRegistered::AFTER, new AfterAvailableSuitesRegistered());
67
        } else {
68
            $this->eventDispatcher->dispatch(new AfterAvailableSuitesRegistered(), AvailableSuitesRegistered::AFTER);    
0 ignored issues
show
Documentation introduced by
new \Bex\Behat\ChooseTes...lableSuitesRegistered() is of type object<Bex\Behat\ChooseT...ilableSuitesRegistered>, but the function expects a object<Symfony\Contracts\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
        }
70
71
        return $result;
72
    }
73
}
74