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.

PlaceholderArgumentTransformer   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 59
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B supportsDefinitionAndArgument() 0 21 6
A transformArgument() 0 15 3
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