Backgroundable::BackgroundDispatcher()   B
last analyzed

Complexity

Conditions 7
Paths 16

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 7.551
c 0
b 0
f 0
cc 7
eloc 15
nc 16
nop 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Dictionary;
4
5
use Behat\Behat\Hook\Scope\BeforeStepScope;
6
7
trait Backgroundable
8
{
9
    private $HOOK_BEFORE_BACKGROUND = 'BeforeBackground';
10
    private $HOOK_AFTER_BACKGROUND  = 'AfterBackground';
11
12
    private $inBackground = false;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
13
    private $afterBackground = false;
14
15
    /**
16
     * @BeforeStep
17
     **/
18
    public function BackgroundDispatcher(BeforeStepScope $event)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
19
    {
20
        $feature = $event->getFeature();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
21
        $background = $feature->getBackground() ?: null;
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...
22
        $steps = null === $background ? [] : $background->getSteps();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
23
        $underBackground = in_array($event->getStep(), $steps);
24
25
        if (null === $background && false === $this->afterBackground) {
26
            $this->displachEvent($this->HOOK_BEFORE_BACKGROUND, $event);
27
            $this->displachEvent($this->HOOK_AFTER_BACKGROUND, $event);
28
            $this->afterBackground = true;
29
        } elseif ($underBackground !== $this->inBackground) {
30
            if (true === $underBackground) {
31
                $this->displachEvent($this->HOOK_BEFORE_BACKGROUND, $event);
32
            } else {
33
                $this->displachEvent($this->HOOK_AFTER_BACKGROUND, $event);
34
            }
35
36
            $this->inBackground = $underBackground;
37
        }
38
    }
39
40
    protected function displachEvent($name, $event)
41
    {
42
        $methods = $this->getHookMethodsByName($name);
43
44
        foreach ($methods as $method) {
45
            $this->$method($event);
46
        }
47
    }
48
49
    protected function getHookMethodsByName($name)
50
    {
51
        $methods = [];
52
        $rfl = new \ReflectionClass($this);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
53
54
        foreach ($rfl->getMethods() as $method) {
55
            $comments = explode("\n", $method->getDocComment());
56
57
            $tags = [];
58
            foreach ($comments as $comment) {
59
                if (preg_match('/@(\w*)/', $comment, $tags)) {
60
                    if (in_array($name, $tags)) {
61
                        $methods[] = $method->name;
62
                    }
63
                }
64
            }
65
        }
66
67
        return array_unique($methods);
68
    }
69
}
70