TokensReplacementsRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @author Alexei Gorobet <[email protected]>
4
 */
5
namespace Behat\TokensExtension;
6
7
use Behat\Testwork\Call\Callee;
8
use Behat\Testwork\Environment\Environment;
9
use Behat\Testwork\Environment\EnvironmentManager;
10
use Behat\TokensExtension\Call\TokensReplacement;
11
12
/**
13
 * Provides token replacement using environment manager.
14
 */
15
final class TokensReplacementsRepository
16
{
17
    /**
18
     * @var EnvironmentManager
19
     */
20
    private $environmentManager;
21
22
    /**
23
     * Initializes repository.
24
     *
25
     * @param EnvironmentManager $environmentManager
26
     */
27
    public function __construct(EnvironmentManager $environmentManager)
28
    {
29
        $this->environmentManager = $environmentManager;
30
    }
31
32
    /**
33
     * Returns all available definitions for a specific environment.
34
     *
35
     * @param Environment $environment
36
     *
37
     * @return TokensReplacement[]
38
     */
39
    public function getEnvironmentTokensReplacements(Environment $environment)
40
    {
41
        return array_filter(
42
            $this->environmentManager->readEnvironmentCallees($environment),
43
            function (Callee $callee) {
44
                return $callee instanceof TokensReplacement;
45
            }
46
        );
47
    }
48
}
49