KernelAwareClassGenerator::supportsSuiteAndClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Behat Symfony2Extension.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\Symfony2Extension\Context\ContextClass;
12
13
use Behat\Behat\Context\ContextClass\ClassGenerator;
14
use Behat\Symfony2Extension\Suite\SymfonyBundleSuite;
15
use Behat\Testwork\Suite\Suite;
16
17
/**
18
 * @author Christophe Coevoet <[email protected]>
19
 */
20
final class KernelAwareClassGenerator implements ClassGenerator
21
{
22
    /**
23
     * @var string
24
     */
25
    private static $template = <<<'PHP'
26
<?php
27
28
{namespace}use Behat\Behat\Context\SnippetAcceptingContext;
29
use Behat\Gherkin\Node\PyStringNode;
30
use Behat\Gherkin\Node\TableNode;
31
use Behat\Symfony2Extension\Context\KernelAwareContext;
32
use Symfony\Component\HttpKernel\KernelInterface;
33
34
/**
35
 * Behat context class.
36
 */
37
class {className} implements SnippetAcceptingContext, KernelAwareContext
38
{
39
    /**
40
     * @var KernelInterface
41
     */
42
    private $kernel;
43
44
    /**
45
     * Sets Kernel instance.
46
     * This method will be automatically called by Symfony2Extension ContextInitializer.
47
     *
48
     * @param KernelInterface $kernel
49
     */
50
    public function setKernel(KernelInterface $kernel)
51
    {
52
        $this->kernel = $kernel;
53
    }
54
}
55
56
PHP;
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function supportsSuiteAndClass(Suite $suite, $classname)
62
    {
63
        return $suite instanceof SymfonyBundleSuite;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function generateClass(Suite $suite, $contextClass)
70
    {
71
        $fqn = $contextClass;
72
73
        $namespace = '';
74
        if (false !== $pos = strrpos($fqn, '\\')) {
75
            $namespace = 'namespace ' . substr($fqn, 0, $pos) . ";\n\n";
76
            $contextClass = substr($fqn, $pos + 1);
77
        }
78
79
        return strtr(
80
            static::$template,
0 ignored issues
show
Comprehensibility introduced by
Since Behat\Symfony2Extension\...rnelAwareClassGenerator is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
81
            array(
82
                '{namespace}' => $namespace,
83
                '{className}' => $contextClass,
84
            )
85
        );
86
    }
87
}
88