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

supportsDefinitionAndArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
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
16
/**
17
 * Transform a number to string,
18
 * Any number along inside a parameter is considered a number
19
 *
20
 * @example 1 => (int) 1
21
 * @example "1" => (int) 1
22
 *
23
 * @see     TransformAnyValueToString to scape types
24
 */
25
class TransformStringToNumber implements ArgumentTransformer
26
{
27
    private const PATTERN = '/^(\d+)$/';
28
29
    public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
30
    {
31
        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...
32
    }
33
34
    public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
35
    {
36
        return (int) $argumentValue;
37
    }
38
}
39