GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

supportsDefinitionAndArgument()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6.0359

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 9
cts 10
cp 0.9
rs 8.7624
c 0
b 0
f 0
cc 6
eloc 10
nc 6
nop 3
crap 6.0359
1
<?php
2
declare(strict_types = 1);
3
4
namespace espend\Behat\PlaceholderExtension\Transformer;
5
6
use Behat\Behat\Definition\Call\DefinitionCall;
7
use Behat\Behat\Transformation\Transformer\ArgumentTransformer;
8
use espend\Behat\PlaceholderExtension\PlaceholderBagInterface;
9
use espend\Behat\PlaceholderExtension\Utils\PlaceholderUtil;
10
11
/**
12
 * @author Daniel Espendiller <[email protected]>
13
 */
14
class PlaceholderArgumentTransformer implements ArgumentTransformer
15
{
16
    /**
17
     * @var PlaceholderBagInterface
18
     */
19
    private $placeholderBag;
20
21
    /**
22
     * @param PlaceholderBagInterface $placeholderBag
23
     */
24 8
    public function __construct(PlaceholderBagInterface $placeholderBag)
25
    {
26 8
        $this->placeholderBag = $placeholderBag;
27 8
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 4
    public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
33
    {
34 4
        if (!is_string($argumentValue)) {
35
            return false;
36
        }
37
38
        // '%FOO%', '%foo%'
39 4
        if (PlaceholderUtil::isValidPlaceholder($argumentValue)) {
40 1
            return ($placeholders = $this->placeholderBag->all())
41 1
                && isset($placeholders[$argumentValue]);
42
        }
43
44
        // 'foobar%FOO%'
45 3
        foreach ($this->placeholderBag->all() as $key => $value) {
46 3
            if (false !== strpos($argumentValue, $key)) {
47 3
                return true;
48
            }
49
        }
50
51 2
        return false;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 4
    public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
58
    {
59
        // 'foobar%FOO%'
60 4
        foreach ($this->placeholderBag->all() as $key => $value) {
61 4
            $argumentValue = str_replace($key, $value, $argumentValue);
62
        }
63
64
        // '%FOO%', '%foo%'
65 4
        $placeholder = $this->placeholderBag->all();
66 4
        if (isset($placeholder[$argumentValue])) {
67
            return $placeholder[$argumentValue];
68
        }
69
70 4
        return $argumentValue;
71
    }
72
}
73