hasContextClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the SymfonyExtension package.
7
 *
8
 * (c) Kamil Kokot <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace FriendsOfBehat\SymfonyExtension\Context\Environment;
15
16
use Behat\Behat\Context\Environment\ContextEnvironment;
17
use Behat\Testwork\Environment\StaticEnvironment;
18
use Behat\Testwork\Suite\Suite;
19
use FriendsOfBehat\SymfonyExtension\Context\Environment\Handler\ContextServiceEnvironmentHandler;
20
21
/**
22
 * @see ContextServiceEnvironmentHandler
23
 */
24
final class UninitializedSymfonyExtensionEnvironment extends StaticEnvironment implements SymfonyExtensionEnvironment
25
{
26
    /** @var string[] */
27
    private $contexts;
28
29
    /** @var ContextEnvironment */
30
    private $delegatedEnvironment;
31
32
    public function __construct(Suite $suite, array $contexts, ContextEnvironment $delegatedEnvironment)
33
    {
34
        parent::__construct($suite);
35
36
        $this->contexts = $contexts;
37
        $this->delegatedEnvironment = $delegatedEnvironment;
38
    }
39
40
    public function getServices(): array
41
    {
42
        return array_keys($this->contexts);
43
    }
44
45
    public function hasContexts(): bool
46
    {
47
        return count($this->contexts) > 0 || $this->delegatedEnvironment->hasContexts();
48
    }
49
50
    public function getContextClasses(): array
51
    {
52
        return array_merge(array_values($this->contexts), $this->delegatedEnvironment->getContextClasses());
53
    }
54
55
    public function hasContextClass($class): bool
56
    {
57
        return in_array($class, $this->contexts, true) || $this->delegatedEnvironment->hasContextClass($class);
58
    }
59
60
    public function getDelegatedEnvironment(): ContextEnvironment
61
    {
62
        return $this->delegatedEnvironment;
63
    }
64
}
65