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

TransformFixtureNameToGlobalId   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 30
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDefinitionAndArgument() 0 3 1
A transformArgument() 0 5 1
A __construct() 0 4 1
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 fixtures global ID,
20
 * the fixture name should be prefixed with #
21
 *
22
 * @example "#user1" => "VXNlcjox"
23
 */
24
class TransformFixtureNameToGlobalId 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->getFixtureGlobalId($name);
54
    }
55
}
56