UninitialisedContextServiceEnvironment   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerContextService() 0 4 1
A getContextServices() 0 4 1
A hasContexts() 0 4 1
A getContextClasses() 0 4 1
A hasContextClass() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ContextServiceExtension 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\ContextServiceExtension\Context\Environment;
15
16
use Behat\Testwork\Environment\StaticEnvironment;
17
use FriendsOfBehat\ContextServiceExtension\Context\Environment\Handler\ContextServiceEnvironmentHandler;
18
19
/**
20
 * @internal
21
 *
22
 * @see ContextServiceEnvironmentHandler
23
 */
24
final class UninitialisedContextServiceEnvironment extends StaticEnvironment implements ContextServiceEnvironment
25
{
26
    /**
27
     * @var string[]
28
     */
29
    private $contextServices = [];
30
31
    /**
32
     * @param string $serviceId
33
     * @param string $serviceClass
34
     */
35
    public function registerContextService(string $serviceId, string $serviceClass): void
36
    {
37
        $this->contextServices[$serviceId] = $serviceClass;
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function getContextServices(): array
44
    {
45
        return array_keys($this->contextServices);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function hasContexts(): bool
52
    {
53
        return count($this->contextServices) > 0;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getContextClasses(): array
60
    {
61
        return array_values($this->contextServices);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function hasContextClass($class): bool
68
    {
69
        return in_array($class, $this->contextServices, true);
70
    }
71
}
72