Passed
Pull Request — master (#9)
by Rafael
03:29
created

TransformFixtureNameToObject::transformArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
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\Transformer;
12
13
use Behat\Behat\Definition\Call\DefinitionCall;
14
use Behat\Behat\Transformation\Transformer\ArgumentTransformer;
15
use Symfony\Component\HttpKernel\KernelInterface;
16
use Ynlo\GraphQLBundle\Behat\Fixtures\FixtureManager;
17
18
/**
19
 * Transform named fixtures to object reference,
20
 * the fixture name should be prefixed with @
21
 *
22
 * @example "@user1" => User (object)
23
 */
24
class TransformFixtureNameToObject implements ArgumentTransformer
25
{
26
    private const PATTERN = '/^@/';
27
28
    /**
29
     * @var KernelInterface
30
     */
31
    protected $kernel;
32
33
    /**
34
     * @var FixtureManager
35
     */
36
    protected $fixtureManager;
37
38
    public function __construct(KernelInterface $kernel, FixtureManager $fixtureManager)
39
    {
40
        $this->kernel = $kernel;
41
        $this->fixtureManager = $fixtureManager;
42
    }
43
44
    public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
45
    {
46
        return preg_match(self::PATTERN, $argumentValue);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match(self::PATTERN, $argumentValue) returns the type integer which is incompatible with the return type mandated by Behat\Behat\Transformati...DefinitionAndArgument() of boolean.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
47
    }
48
49
    public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
50
    {
51
        $name = preg_replace(self::PATTERN, null, $argumentValue);
52
53
        return $this->fixtureManager->getFixture($name);
54
    }
55
}
56