Issues (281)

src/Behat/Context/RouteContext.php (1 issue)

1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[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 Ynlo\GraphQLBundle\Behat\Context;
12
13
use Behat\Behat\Context\Context;
14
use Behat\Behat\Hook\Scope\BeforeStepScope;
15
use Behat\Symfony2Extension\Context\KernelAwareContext;
16
use Symfony\Component\HttpKernel\Kernel;
17
use Symfony\Component\HttpKernel\KernelInterface;
18
use Ynlo\GraphQLBundle\Behat\Client\ClientAwareInterface;
19
use Ynlo\GraphQLBundle\Behat\Client\ClientAwareTrait;
20
use Ynlo\GraphQLBundle\Behat\GraphQLApiExtension;
21
22
final class RouteContext implements Context, KernelAwareContext, ClientAwareInterface
23
{
24
    use ClientAwareTrait;
25
26
    /**
27
     * @var Kernel
28
     */
29
    private $kernel;
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function setKernel(KernelInterface $kernel)
35
    {
36
        $this->kernel = $kernel;
0 ignored issues
show
Documentation Bug introduced by
$kernel is of type Symfony\Component\HttpKernel\KernelInterface, but the property $kernel was declared to be of type Symfony\Component\HttpKernel\Kernel. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
37
    }
38
39
    /**
40
     * @BeforeStep
41
     */
42
    public function beforeStep(BeforeStepScope $scope)
43
    {
44
        $config = GraphQLApiExtension::getConfig();
45
46
        $tags = $scope->getFeature()->getTags();
47
        $featureRoute = null;
48
        foreach ($tags as $tag) {
49
            if (preg_match('/^route:/', $tag)) {
50
                $featureRoute = preg_replace('/^route:/', null, $tag);
51
                break;
52
            }
53
        }
54
        if (!$featureRoute && isset($config['route'])) {
55
            $featureRoute = $config['route'];
56
        }
57
58
        if ($featureRoute) {
59
            $endpoint = $this->kernel->getContainer()->get('router')->generate($featureRoute);
60
            $this->client->setEndpoint($endpoint);
61
        }
62
    }
63
}
64